题目描述:
Given a string, determine if a permutation of the string could form a palindrome.
Example 1:
Input: "code" Output: false
Example 2:
Input: "aab" Output: true
Example 3:
Input: "carerac" Output: true
class Solution {
public:
bool canPermutePalindrome(string s) {
unordered_map<char,int> count;
for(char c:s) count[c]++;
bool flag=false;
for(auto x:count)
{
if(x.second%2==1)
{
if(!flag) flag=true;
else return false;
}
}
return true;
}
};