package leetcode

// 409. Longest Palindrome
func longestPalindrome(s string) int {
	bytes := make(map[byte]int, 0)
	for i := 0; i < len(s); i++ {
		b := s[i]
		count := bytes[b]
		bytes[b] = count + 1
	}

	res := 0
	hasPrime := false
	for _, count := range bytes {
		x, y := count/2, count%2
		res += x * 2
		if y == 1 {
			hasPrime = true
		}
	}

	if hasPrime {
		res++
	}
	return res
}

package leetcode

// 409. Longest Palindrome
func longestPalindrome(s string) int {
	bytes := make(map[byte]int, 0)
	count := 0
	for i := 0; i < len(s); i++ {
		b := s[i]
		_, ok := bytes[b]
		if ok {
			count++
			delete(bytes, b)
		} else {
			bytes[b] = 1
		}
	}
	if len(bytes) > 0 {
		return count*2 + 1
	}
	return count * 2
}

Fix 409. Longest Palindrome to use single loop
Fix 409. Longest Palindrome to use single loop
