Last active
August 21, 2017 07:11
-
-
Save luojiyin1987/01db2661e423d8d8bf00b19f3df88082 to your computer and use it in GitHub Desktop.
Longest Palindrome
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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