本题题目要求如下:
Given a string, determine if a permutation of the string could form a palindrome.
For example,
"code"
-> False, "aab"
->
True, "carerac"
-> True.
class Solution {
public:
bool canPermutePalindrome(string s) {
vector<int> hashmap(256, 0);
for (int i = 0; i < s.length(); ++i) {
hashmap[s[i]]++;
}
int cnt = 0;
for (int i = 0; i < 256; ++i) {
if (hashmap[i] % 2 == 1) {
++cnt;
}
}
return !(cnt > 1);
}
};