Attention! The string may contain characters other than lower case alphabet. C++ code is attached


  • 0
    class Solution {
    public:
        bool canPermutePalindrome(string s) {
            vector<int> ch(128, 0);
            int count = 0;
            
            for(int i = 0; i < s.length(); i++){
                ch[s[i]]++;
            }
            
            for(int i = 0;i < 128; i++){
                if (ch[i] % 2) count++;
            }
            
            return count <= 1;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.