Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Last active August 21, 2017 07:11
Show Gist options
  • Save luojiyin1987/01db2661e423d8d8bf00b19f3df88082 to your computer and use it in GitHub Desktop.
Save luojiyin1987/01db2661e423d8d8bf00b19f3df88082 to your computer and use it in GitHub Desktop.
Longest Palindrome
func longestPalindrome(s string) int {
temp := make(map[int32]int)
count := 0
var oddNumber []int
for _, v := range s {
temp[v]++
}
for _, v := range temp {
if v %2 == 0 {
count += v
}else {
count = count +v -1
oddNumber = append(oddNumber,v)
}
}
if len(oddNumber) > 0 {
count += 1
}
return count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment