Leetcode 266 Solution
This article provides solution to leetcode question 266 (palindrome-permutation)
Access this page by simply typing in "lcs 266" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/palindrome-permutation
Solution
class Solution {
public:
bool canPermutePalindrome(string s) {
int cnt[256] = {0};
int odd_cnt = 0;
for (auto ch : s)
{
if (++cnt[ch] % 2 == 1)
odd_cnt++;
else
odd_cnt--;
}
return s.size() % 2 == 0 && odd_cnt == 0 || s.size() % 2 == 1 && odd_cnt == 1;
}
};