额额,例子是错的。。。我为什么要点开。。。。。。。
class Solution {
public:
bool canPermutePalindrome(string s) {
unordered_map<char,int>hash;
for(int i = 0; i < s.size(); i++)
{
hash[s[i]]++;
}
int cnt = 0; //字母出现个数只能有一次是奇数
unordered_map<char,int>::iterator it;
for(it = hash.begin(); it != hash.end(); it++)
{
if(it->second % 2 == 1)
{
cnt++;
if(cnt == 2)
{
return false;
}
}
}
return true;
}
};