[LeetCode] 169. Majority Element
質問リンク
https://leetcode.com/problems/majority-element/
コミットコード
🙄 Collectionsモジュール-Counterの使用
結果値(return)はバイナリ形式で出力されます.
このとき要素の個数が多いものから出力します.
🙄 .items()
キー値ペアを一度に抽出する方法
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()
キー値ペアを一度に抽出する方法
Reference
この問題について([LeetCode] 169. Majority Element), 我々は、より多くの情報をここで見つけました https://velog.io/@hizzang920/LeetCode-169.-Majority-Elementテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol