10ms Java Solution


  • 0
    H

    public class Solution {
    public int longestPalindrome(String s) {
    if(s.length()==0||s==null) return 0;
    int[] tmp=new int[58];
    int count=0,res=0;
    for(char c:s.toCharArray()){
    tmp[c-'A']++;
    }
    for(int i=0;i<58;i++){
    if(tmp[i]%2!=0){
    res+=tmp[i]-1;
    count=1;
    }else{
    res+=tmp[i];
    }
    }
    return res+count;
    }
    }


Log in to reply
 

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