Simple Java beat 99.67%


  • 3
    E
    public int longestPalindrome(String s) {
            int[] chars = new int[128];
            char[] t = s.toCharArray();
            for(char c:t){
                chars[c]++;
            }
            int single = 0;
            for(int n:chars){
                if(n%2!=0){
                    single++;
                }
            }
            return single>1?t.length-single+1:t.length;
        }
    

Log in to reply
 

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