[LeetCode] Palindrome Permutation

266. Palindrome Permutation

Given a string s, return true if a permutation of the string could form a palindrome and false otherwise.

1
2
3
4
5
6
7
8
9
10
class Solution {
public:
bool canPermutePalindrome(string s) {
unordered_map<char,int> freq;
for(auto ch : s) freq[ch] += 1;
int cnt = 0;
for(auto [_,v] : freq) cnt += v % 2;
return cnt <= 1;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/07/30/PS/LeetCode/palindrome-permutation/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.