18ms java


  • 0
    A
    public class Solution {
        public int longestPalindrome(String s){
            
                 int slength =0;
                int result=0;
                if(s==null)return 0;
                if(s.length()==1) return 1;
                Map<Character,Integer> maps = new HashMap<Character, Integer>();
                if(s!=null){
                    slength=s.length();
                    for(char c:s.toCharArray()){
                        if(maps.containsKey(c)){
                            maps.remove(c);
                        }else{
                            maps.put(c,1);
                        }
                    }
                    for(Integer length:maps.values()){
                        result +=length;
                    }
                }
             return result>=1?slength-result+1:slength;
        }
    }
    

Log in to reply
 

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