409. 最长回文串
作者:
上杉丶零 | 来源:发表于
2020-03-19 17:38 被阅读0次class Solution {
public int longestPalindrome(String s) {
if (s == null || "".equals(s)) {
return 0;
}
int[] counts = new int[75];
for (char c : s.toCharArray()) {
counts[c - '0']++;
}
int length = 0;
boolean hasOdd = false;
for (int count : counts) {
if (count == 0) {
continue;
}
length += count / 2 * 2;
if (!hasOdd && count % 2 == 1) {
hasOdd = true;
}
}
if (hasOdd) {
length += 1;
}
return length;
}
}

image.png
本文标题:409. 最长回文串
本文链接:https://www.haomeiwen.com/subject/towlyhtx.html
网友评论