[LeetCode] 169. Majority Element


質問リンク
https://leetcode.com/problems/majority-element/
コミットコード
from collections import Counter
class Solution:
    def majorityElement(self, nums: List[int]) -> int:
        half_len = len(nums)/2
        counter = Counter(nums)
        for key, value in counter.items():
            if value > half_len:
                return key
に答える
🙄 Collectionsモジュール-Counterの使用
結果値(return)はバイナリ形式で出力されます.
このとき要素の個数が多いものから出力します.
🙄 .items()
キー値ペアを一度に抽出する方法