concise java solution


  • 0
    D
      public int longestPalindrome(String s) {
            int[] count = new int[58]; // gap between z and A in ascii table
            for(char a: s.toCharArray()){
                if(count[a-'A'] >0) count[a-'A']--;
                else count[a-'A']++;
            }
            int counter = 0; 
            for(int i:count){
                if(i>0) counter++;
            }
            return s.length()-counter+(counter>0?1:0);
        }
    

Log in to reply
 

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