| https://leetcode.com/problems/longest-palindrome/description/ | Easy |
|---|
class Solution {
fun longestPalindrome(s: String): Int {
val cnt = IntArray(128)
var i = 0
val n = s.length
while (i < n) {
cnt[s[i].code]++
i++
}
var res = 0
var hasOdd = false
i = 0
while (i < 128) {
val c = cnt[i]
res += c and -2
if ((c and 1) == 1) hasOdd = true
i++
}
return if (hasOdd) res + 1 else res
}
}