LintCode 158
写出一个函数 anagram(s, t)
去判断两个字符串是否是颠倒字母顺序构成的
样例
给出 s="abcd"
,t="dcab"
,返回 true
该题可以将两个单词进行排序比较即可。复杂度nlogn,排序的复杂度。
class Solution {
public:
/**
* @param s: The first string
* @param b: The second string
* @return true or false
*/
bool anagram(string s, string t) {
// write your code here
vector<int > s1,s2;
for(auto c:s)
s1.push_back(c);
for(auto c:t)
s2.push_back(c);
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
return s1 == s2;
}
};