@@ -0,0 +1,1440 @@
+package com.freetymekiyan.algorithms.level.easy;%0A%0A/**%0A * 409. Longest Palindrome%0A * %3Cp%3E%0A * Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can%0A * be built with those letters.%0A * %3Cp%3E%0A * This is case sensitive, for example %22Aa%22 is not considered a palindrome here.%0A * %3Cp%3E%0A * Note:%0A * Assume the length of given string will not exceed 1,010.%0A * %3Cp%3E%0A * Example:%0A * %3Cp%3E%0A * Input:%0A * %22abccccdd%22%0A * %3Cp%3E%0A * Output:%0A * 7%0A * %3Cp%3E%0A * Explanation:%0A * One longest palindrome that can be built is %22dccaccd%22, whose length is 7.A%0A * %3Cp%3E%0A * Related Topics: Hash Table%0A * %3Cp%3E%0A * Similar Questions: Palindrome Permutation (E)%0A * %3Cp%3E%0A * Companies: Microsoft%0A */%0Apublic class LongestPalindrome %7B%0A%0A  /**%0A   * Hash Table.%0A   * From input string we can get character counts.%0A   * Characters with even count can all be used in a palindrome.%0A   * For characters with odd count, half can be used in a palindrome.%0A   * If the current length is even, the 1 remaining character can be put in the middle.%0A   * If the current length is odd, we can't do anything.%0A   */%0A  public int longestPalindrome(String s) %7B%0A    final int%5B%5D counts = new int%5B128%5D;%0A    for (char c : s.toCharArray()) %7B%0A      counts%5Bc%5D++;%0A    %7D%0A%0A    int maxLength = 0;%0A    for (final int c : counts) %7B%0A      maxLength += c / 2 * 2;%0A      if (maxLength %25 2 == 0 && c %25 2 == 1) %7B%0A        maxLength++;%0A      %7D%0A    %7D%0A    return maxLength;%0A  %7D%0A%7D

Add 408 Longest Palindrome