๐ฅ Code-kata week2-2
๋ฌธ์
์ซ์๋ก ์ด๋ฃจ์ด์ง ๋ฐฐ์ด์ธ nums๋ฅผ ์ธ์๋ก ์ ๋ฌํฉ๋๋ค.
์ซ์์ค์์ ๊ณผ๋ฐ์(majority, more than a half)๊ฐ ๋์ ์ซ์๋ฅผ ๋ฐํํด์ฃผ์ธ์.
์๋ฅผ ๋ค์ด,
nums = [3,2,3]
return 3
nums = [2,2,1,1,1,2,2]
return 2
ํ์ด
''
์ ๋ฐํํ๋ค def more_than_half(nums):
new_list = []
for i in nums:
cnt = nums.count(i)
if cnt > len(nums)/2:
new_list.append(i)
if len(new_list) == 0:
return ''
else:
return new_list[0]