Simple Java solution using boolean[ ] 5 lines, 8ms


  • 0
    D
    public int longestPalindrome(String s) {
            boolean[] isOdd = new boolean[128];
            for(char c : s.toCharArray()) 
                isOdd[c] = !isOdd[c];
            int count = 0;
            for (boolean b : isOdd) 
                if (b) amend++;
           return Math.min(s.length(), s.length() - count + 1);
        }
    

  • 0
    Y
    This post is deleted!

Log in to reply
 

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