Simple Java solution


  • 0
    N
        public int longestPalindrome(String s) {
          int[] ch = new int[65];
            int count=0;
            for(int i=0;i<s.length();i++){
               int index = s.charAt(i) - 'A';
               if(index>=0){
                ch[index]++;
                if(ch[index]%2==0){
                count+=2;
                ch[index]=0;
                }
               }
            }
            if(count<s.length() || count==0){
            return count+1;
            }
            
            return count;
        }
    }

  • 0
    K

    very good solution


Log in to reply
 

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