Leetcode 266 Solution

This article provides solution to leetcode question 266 (palindrome-permutation)

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;
    }
};