Java 4 lines beats 90%


  • 1
    Y
        public int longestPalindrome(String s) {
            int arr[] = new int[1 << 7], l = 0;
            for (char c : s.toCharArray()) arr[c]++;
            for (int i : arr) l += i >> 1 << 1;
            return l == s.length() ? l : l + 1;
        }
    

Log in to reply
 

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