TIL81. CodeKata (7)

Jaeyeon·2021년 4월 6일
0
post-thumbnail

문제

숫자로 이루어진 배열인 nums를 인자로 전달합니다.

숫자중에서 과반수(majority, more than a half)가 넘은 숫자를 반환해주세요.

예를 들어,

nums = [3,2,3]
return 3

nums = [2,2,1,1,1,2,2]
return 2

가정

nums 배열의 길이는 무조건 2 이상입니다.

나의 풀이

def more_than_half(nums):
    result =[i for i in nums if nums.count(i) > len(nums)/2]
    return list(set(result))[0]
profile
생각하는 개발자 되기

0개의 댓글