Problem
Given two strings,write a method to decide if one is a permutation of the other.
Note:
0 <= len(s1) <= 100
0 <= len(s2) <= 100
Example1
Input: s1 = “abc”, s2 = “bca”
Output: true
Example2
Input: s1 = “abc”, s2 = “bad”
Output: false
Solution
哈希表或排序
class Solution {
public:
bool CheckPermutation(string s1, string s2) {
sort(s1.begin(),s1.end());
sort(s2.begin(),s2.end());
return s1 == s2;
}
};