package main
import "fmt"
/**
给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串。
在构造过程中,请注意区分大小写。比如 "Aa" 不能当做一个回文字符串。
*/
func main() {
a := "AZazbccccdd"
fmt.Println(longestPalindrome(a))
}
func longestPalindrome(s string) int {
var count [58]int
// 记录各个字符出现的次数
for _, v := range s {
count[v-'A']++
}
// 记录字符出现为奇数加一
temp := 0
res := 0
for _, v := range count {
less := v % 2
if less == 0 {
res += v
} else if v > 1 {
res += v - 1
temp = 1
} else {
temp = 1
}
}
return res + temp
}