c++ hash solution


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

Log in to reply
 

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