LeetCode 409. 最长回文串

题目描述

🔥 409. 最长回文串

思路分析

思路描述

参考代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
func longestPalindrome(s string) int {
	res := 0
	odd := false
	freq := make(map[rune]int)
	for _, c := range s {
		freq[c]++
	}
	for _, count := range freq {
		if count%2 == 0 {
			res += count
		} else {
			res += count - 1
			odd = true
		}
	}
	if odd {
		res += 1
	}
	return res
}

🍏 点击查看 Java 题解

1
write your code here

相似题目

题目 难度 题解
回文排列 Easy  
本文作者:
本文链接: https://hgnulb.github.io/blog/65333411
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处!