simple java solution ez to understand


  • 0
    X
    public int longestPalindrome(String s) {
        char[] letters = new char[52];
        for(int i=0;i<s.length();i++){
            int c = s.charAt(i)-'a';
            if(c<0) c+=57;
            letters[c] ^= 1;
        }
        int res=0;
        for(int i=0;i<letters.length;i++){
            if(letters[i]==1) res+=1;
        }
        
        return res<=1?s.length():s.length()-(res-1);
    }

Log in to reply
 

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