Given a string, determine if a permutation of the string could form a palindrome.
For example,"code"
-> False, "aab"
-> True, "carerac"
-> True.
要点:学习如何iterate一个unordered_map。
class Solution {
public:
bool canPermutePalindrome(string s) {
unordered_map<char, int> dict;
for (int i = , n = s.size(); i < n; i++) {
if (dict.count(s[i]) == )
dict.insert(make_pair(s[i], ));
else dict[s[i]]++;
}
int oddCount = ;
for (auto it = dict.begin(); it != dict.end(); it++) {
if (it->second % ) oddCount++;
if (oddCount > ) return false;
}
return true;
}
};