Four-line Easiest Java solution, challenge me!


  • 0
    O
    public int longestPalindrome(String s) {
            int total = 0;
            int[] ca = new int[256];
            for (int i=0; i<s.length(); i++) if (++ca[s.charAt(i)] % 2 == 0) total += 2;
            return total<s.length()?total+1:total;
    }
    

Log in to reply
 

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