Java solution, easy understand, using int[256]


  • 0
    H
        public boolean canPermutePalindrome2(String s) {
            int[] table = new int[256];
            int oddCount = 0;
    
            for (char c : s.toCharArray()) {
              table[c]++;
            }
            
            for (int k : table) {
                if (k % 2 != 0) {
                    oddCount++;
                }
            }
            
            return oddCount == 0 || oddCount == 1;
        }
    

Log in to reply
 

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