题目链接:https://leetcode.com/problems/valid-anagram/description/
先sort排序,再compare比较大小。
class Solution {
public:
bool isAnagram(string s, string t) {
int slength = s.length();
int tlength = t.length();
if(slength != tlength){
return false;
}
sort(s.begin(),s.end());
sort(t.begin(),t.end());
if(s.compare(t) == 0){
return true;
}else{
return false;
}
}
};