Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 답안
- def solution(A):
- import random
- count = []
- for i in range(len(A)):
- count.append(A.count(A[i]))
- temp = list(count)
- temp.sort()
- if temp[len(temp)-1] > len(A) / 2:
- result = count.index(temp[len(temp)-1])
- else:
- result = -1
- return result
- # 추가
- import random
- count = []
- idx = []
- for i in range(len(A)):
- count.append(A.count(A[i]))
- temp = list(count)
- temp.sort()
- if temp[len(temp)-1] > len(A) / 2:
- result = count.index(temp[len(temp)-1])
- for j in range(len(count)):
- if count[j] == temp[len(temp)-1]:
- idx.append(j)
- if len(idx) <= 1:
- result = idx[0]
- else:
- random = random.randint(0, len(idx))
- result = idx[random]
- else:
- result = -1
- result
Add Comment
Please, Sign In to add comment