Guest User

Untitled

a guest
Dec 14th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. # 답안
  2. def solution(A):
  3. import random
  4. count = []
  5.  
  6. for i in range(len(A)):
  7. count.append(A.count(A[i]))
  8.  
  9. temp = list(count)
  10. temp.sort()
  11.  
  12. if temp[len(temp)-1] > len(A) / 2:
  13. result = count.index(temp[len(temp)-1])
  14. else:
  15. result = -1
  16.  
  17. return result
  18.  
  19.  
  20.  
  21. # 추가
  22. import random
  23. count = []
  24. idx = []
  25. for i in range(len(A)):
  26. count.append(A.count(A[i]))
  27.  
  28. temp = list(count)
  29. temp.sort()
  30.  
  31. if temp[len(temp)-1] > len(A) / 2:
  32. result = count.index(temp[len(temp)-1])
  33.  
  34. for j in range(len(count)):
  35. if count[j] == temp[len(temp)-1]:
  36. idx.append(j)
  37. if len(idx) <= 1:
  38. result = idx[0]
  39. else:
  40. random = random.randint(0, len(idx))
  41. result = idx[random]
  42. else:
  43. result = -1
  44.  
  45. result
Add Comment
Please, Sign In to add comment