Given two strings of equal length, you have to tell whether they both strings are identical.
Two strings S1 and S2 are said to be identical, if any of the permutation of string S1 is equal to the string S2. See Sample explanation for more details.
Example:
Input: a = "sumit", b = "mitsu"
Output: YES
Approach
C++
#include <bits/stdc++.h>using namespace std;void twoStrings(string a, string b){sort(a.begin(), a.end());sort(b.begin(), b.end());if (a == b)cout << "YES\n";elsecout << "NO\n";}int main(){string a = "sumit", b = "mitsu";twoStrings(a, b);return 0;}
No comments:
Post a Comment