## 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.```

Code:

``````public class Solution {
public int longestPalindrome(String s) {
int result = 0;

if (s != null && s.length() > 0) {
int[] hash = new int[100];
for (char vs : s.toCharArray()) {
if (hash[vs - 'A'] == 1) {
result += 2;
hash[vs - 'A']--;
} else {
hash[vs - 'A']++;
}
}
for (int vh : hash) {
if (vh != 0) {
result++;
break;
}
}
}

return result;
}
}``````

### 初雪之音

【LeetCode】409. Longest Palindrome （java实现）

BookShu
2016/11/04
145
0
[leetcode] Longest Palindromic Substring

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. ht......

jdflyfly
2014/06/24
614
0
[LeetCode] Shortest Palindrome 最短回文串

Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this tran......

2017/12/02
0
0
LeetCode Question Difficulty Distribution 问题难度和频率分布

Leetcode问题难度和频率分布表 引用自： https://zephyrusara.blogspot.jp/2014/07/leetcode-question-difficulty.html LeetCode Question Difficulty Distribution : Sheet1......

xidiancoder
2017/09/10
0
0
topcoder题目及我的程序（4）——find reversed string （算法1）

Problem Statement ???? You are given a String input. You are to find the longest substring of input such that the reversal of the substring is also a substring of input. In case......

2012/03/09
265
0

IOC的学习(1)

1.IOC理论概要 java中，一个对象A怎么才能调用对象B？ 当一个对象的构建，需要多个其他对象时，对象和对象有复杂的构建关系。spring帮助我们维系对象的依赖关系，降低系统的实现成本，前提是...

26分钟前
1
0
Spring 的 getBean 方法源码解析

TSMYK
29分钟前
0
0

35分钟前
1
0
PTA-基础编程题目集-7-14 求整数段和

niithub
35分钟前
4
0
Spring Qualifier的使用

52iSilence7
38分钟前
1
0