My 5-line Simple JAVA solution


  • 1
    F
    public class Solution {
        public int longestPalindrome(String s) {
            int[] count = new int[Math.abs('A' - 'z')+1];
            int ans = 0;
            for(int i = 0; i< s.length(); i++) count[s.charAt(i) - 'A']++; 
            for(int n: count) ans += n/2;
            return Math.min(ans*2+1, s.length());
        }
    }
    

Log in to reply
 

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