Very easy to understand Java solution


  • 0
    L
        public int longestPalindrome(String s) {
            HashSet<Character> set = new HashSet<>();
            int len = s.length();
            for(int i=0;i<len;i++){
                if(!set.contains(s.charAt(i))){
                    set.add(s.charAt(i));
                }else{
                    set.remove(s.charAt(i));
                }
            }
            return set.size()==0?len-set.size():len-set.size()+1;
         }
    }

Log in to reply
 

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