본문 바로가기
python-algorithm

leetcode 169. Majority Element

by 무적김두칠 2022. 4. 8.

1
2
3
4
5
class Solution:
    def majorityElement(self, nums: List[int]) -> int:
        nums_set=list(set(nums))
        for i in nums_set:
            if nums.count(i)>=len(nums)/2 : return(i); break
cs
반응형

'python-algorithm' 카테고리의 다른 글

leetcode 682. Baseball Game  (0) 2022.04.11
leetcode 1507. Reformat Date  (0) 2022.04.08
leetcode 258. Add Digits  (0) 2022.04.08
leetcode 1550. Three Consecutive Odds  (0) 2022.04.04
leetcode 1800. Maximum Ascending Subarray Sum  (0) 2022.04.04

댓글