Java 8ms Solution:


  • 0

    public int longestPalindrome(String s) {
    int table[] = new int[128];
    int len=0;
    int count=0;
    for(char c: s.toCharArray()) table[c]++;

        for(int i=0; i< table.length; i++){
            if(table[i]>1 && table[i]%2 ==0){
                len+=table[i];
                }
            if(table[i]>1 && table[i]%2 !=0){
                    len+=(table[i]-1);
                        }
             if(table[i]%2== 1){
                     count=1;
                            }
            }
        return len+count;
        
    }

Log in to reply
 

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