[LeetCode/Python] 169. Majority Element

도니·2025년 9월 12일

Interview-Prep

목록 보기
7/34
post-thumbnail

📌 문제

[LeetCode] 169. Majority Element

📌 풀이

📌 코드 설계

📌 정답 코드

from collections import Counter

class Solution:
    def majorityElement(self, nums: List[int]) -> int:
        n = len(nums)
        majority = n // 2
        print(majority)

        counter = Counter(nums)

        for k, v in counter.items():
            if v > majority:
                return k
profile
Where there's a will, there's a way

0개의 댓글