package com.fishercoder.solutions;

/**
 * 409. Longest Palindrome
 *
 * Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.
 * This is case sensitive, for example "Aa" is not considered a palindrome here.
 *
 * Note:
 * Assume the length of given string will not exceed 1,010.
 *
 * Example:
 * Input:
 * "abccccdd"
 *
 * Output:
 * 7
 *
 * Explanation:
 * One longest palindrome that can be built is "dccaccd", whose length is 7.
 */
public class _409 {
  public static class Solution1 {
    public int longestPalindrome(String s) {
      int[] counts = new int[56];
      for (char c : s.toCharArray()) {
        if (Character.isUpperCase(c)) {
          counts[c - 'A' + 33]++;
        } else {
          counts[c - 'a']++;
        }
      }
      boolean hasOdd = false;
      int len = 0;
      for (int i = 0; i < 56; i++) {
        if (counts[i] % 2 != 0) {
          hasOdd = true;
          if (counts[i] > 1) {
            len += counts[i] - 1;
          }
        } else {
          len += counts[i];
        }
      }
      return hasOdd ? len + 1 : len;
    }
  }
}

@@ -33,502 +33,8 @@
 s;%0A%0A
-/**%0A * 409. Longest Palindrome%0A *%0A * Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters.%0A * This is case sensitive, for example %22Aa%22 is not considered a palindrome here.%0A *%0A * Note:%0A * Assume the length of given string will not exceed 1,010.%0A *%0A * Example:%0A * Input:%0A * %22abccccdd%22%0A *%0A * Output:%0A * 7%0A *%0A * Explanation:%0A * One longest palindrome that can be built is %22dccaccd%22, whose length is 7.%0A */%0A
 publ
@@ -49,16 +49,18 @@
  _409 %7B%0A
+  
   public
@@ -85,16 +85,20 @@
 tion1 %7B%0A
+    
     publ
@@ -130,24 +130,30 @@
 String s) %7B%0A
+      
       int%5B%5D 
@@ -174,16 +174,22 @@
 nt%5B56%5D;%0A
+      
       fo
@@ -223,24 +223,32 @@
 ) %7B%0A        
+     
+   
 if (Characte
@@ -269,32 +269,42 @@
 c)) %7B%0A          
+       
+   
 counts%5Bc - 'A' +
@@ -307,24 +307,32 @@
 A' + 33%5D++;%0A
+        
         %7D el
@@ -328,32 +328,42 @@
        %7D else %7B%0A
+          
           counts
@@ -379,32 +379,54 @@
 ++;%0A        
+        %7D%0A            
 %7D%0A      
 %7D%0A      bool
@@ -409,26 +409,24 @@
     %7D%0A      
-%7D%0A
       boolea
@@ -449,16 +449,22 @@
 ;%0A      
+ 
+     
 int len 
@@ -468,16 +468,22 @@
 en = 0;%0A
+      
       fo
@@ -507,24 +507,32 @@
  56; i++) %7B%0A
+        
         if (
@@ -563,16 +563,26 @@
         
+  
+        
 hasOdd =
@@ -590,32 +590,42 @@
 true;%0A          
+   
+       
 if (counts%5Bi%5D %3E 
@@ -633,32 +633,44 @@
 ) %7B%0A            
+   
+         
 len += counts%5Bi%5D
@@ -685,26 +685,38 @@
         
-%7D%0A
+          %7D%0A  
         
 %7D else %7B
@@ -699,32 +699,38 @@
     %7D%0A          
+      
 %7D else %7B%0A       
@@ -724,32 +724,42 @@
 lse %7B%0A          
+     
+     
 len += counts%5Bi%5D
@@ -772,18 +772,38 @@
     
+     
-%7D%0A
+   %7D%0A     
       
+ 
 %7D%0A
+      
     
@@ -839,16 +839,22 @@
 en;%0A    
-%7D%0A
+    %7D%0A  
   %7D%0A%7D%0A

refactor 409