fork download
  1. class Solution(object):
  2. def majorityElement(self, nums):
  3. """
  4. :type nums: List[int]
  5. :rtype: int
  6. """
  7. most_repeat = 0
  8. count = {}
  9. for i in nums:
  10. if i in count:
  11. count[i] += 1
  12. else:
  13. count[i] = 1
  14.  
  15. # print(count)
  16. for key, val in count.items():
  17. # print(most_repeat, val)
  18. if val > most_repeat:
  19. most_repeat = val
  20. output = key
  21.  
  22. return output
Success #stdin #stdout 0.1s 14036KB
stdin
Standard input is empty
stdout
Standard output is empty