My LeetCode grinding. Trying to do a problem a day.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

main.py 335B

1234567891011121314
  1. class Solution:
  2. def majorityElement(self, nums):
  3. hm = dict()
  4. for n in nums:
  5. if n in hm:
  6. hm[n] += 1
  7. else:
  8. hm[n] = 1
  9. if hm[n] > len(nums) // 2:
  10. return n
  11. s = Solution()
  12. print("Expected: 3")
  13. print("Got:", s.majorityElement([3, 2, 3]))