Simple Java solutions


  • 0
    C
    public class Solution {
        public int longestPalindrome(String s) {
            int longest = 0;
            int[] lowCount = new int[26];
            int[] upCount = new int[26];
            for(char c : s.toCharArray()){
                if(c>='a' && c<='z'){
                    if(++lowCount[c-'a']%2==0){
                        longest+=2;
                    }
                }
                if(c>='A' && c<='Z'){
                    if(++upCount[c-'A']%2==0){
                        longest+=2;
                    }
                }
            }
            if(longest<s.length()){
                longest+=1;
            }
            return longest;
        }
    }
    

    Sometimes I feel stupid to write so many lines of code, especially after I clicking "discuss"🙄️


Log in to reply
 

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