JAVA Solution.beat 94.70%


  • 0
    L

    public int longestPalindrome(String s) {
    char[] ch= s.toCharArray();
    int[] tmp=new int[128];

        for(int i=0;i<ch.length;i++){
            tmp[ch[i]-'A']++;
        }
        
        
        int num=0;
        for(int i=0;i<128;i++){
                num+=tmp[i]/2;
        }
        
        if(num*2<ch.length){
            num=num*2+1;
        }else{
            num=num*2;
        }
        
        
        return num;
    }

Log in to reply
 

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