Java solution


  • 0
    A
    public class Solution {
        public int longestPalindrome(String s) {
            boolean[] vis = new boolean['z'-'A'+1];
            
            for (int i = 0; i < s.length(); i++)
                vis[s.charAt(i)-'A'] = !vis[s.charAt(i)-'A'];
            
            int res = s.length();
            for (int i = 0; i < vis.length; i++)
                if (vis[i])
                    res--;
            
            return Math.min(s.length(), res + 1);
        }
    }
    

Log in to reply
 

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