Java Solution with const array / T : O(1), S : O(1)


  • 0
    J
    public boolean canPermutePalindrome(String s) {
            int[] chs = new int[128];
            int count = 0;
            
            for(char ch : s.toCharArray()){
                chs[ch]++;
                if(chs[ch] % 2 == 0){
                    count--;
                }
                else{
                    count++;
                }
            }
            
            return (count < 2);
        }
    

Log in to reply
 

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