728x90

 

- 주제 : 그리디

- 링크 : https://leetcode.com/problems/longest-palindrome/

from collections import Counter

class Solution:
    def longestPalindrome(self, s: str) -> int: 
        counts = Counter(s)
        length = 0
        odd_found = False
    
        for count in counts.values():
            if count % 2 == 0:
                length += count
            else:
                length += count - 1
                odd_found = True

        if odd_found:
            length += 1
    
        return length

 

알고리즘 강의를 들어야할까....
일단 문제인거.
그리디, 그래프, dfs, bfs, 스택, 큐, 완전탐색
ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
다문제다
728x90

+ Recent posts