""" 0409.1 - Longest Palindrome - Solution 1 - Greedy with Character Counting """
#####################################################################################
# Imports
#####################################################################################
from collections import Counter
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def longestPalindrome(self, s: str) -> int:
"""Longest Palindrome Function"""
counts = Counter(s)
result = 0
for count in counts.values():
result += count // 2 * 2
if result < len(s):
result += 1
return result
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().longestPalindrome("abccccdd")) # 7
print(Solution().longestPalindrome("a")) # 1
print(Solution().longestPalindrome("Aa")) # 1
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()
""" 0409.2 - Longest Palindrome - Solution 2 - Greedy with Running Pair Count """
#####################################################################################
# Imports
#####################################################################################
from collections import defaultdict
#####################################################################################
# Classes
#####################################################################################
class Solution:
"""Solution Class"""
def longestPalindrome(self, s: str) -> int:
"""Longest Palindrome Function"""
count = defaultdict(int)
res = 0
for c in s:
count[c] += 1
if count[c] % 2 == 0:
res += 2
return res + (res < len(s))
#####################################################################################
# Functions
#####################################################################################
def testcase():
"""Test Function"""
print(Solution().longestPalindrome("abccccdd")) # 7
print(Solution().longestPalindrome("a")) # 1
print(Solution().longestPalindrome("Aa")) # 1
#####################################################################################
# Main
#####################################################################################
if __name__ == "__main__":
testcase()