My LeetCode grinding. Trying to do a problem a day.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

main.py 442B

1234567891011121314151617181920
  1. class Solution:
  2. def countElements(self, arr):
  3. hm = dict()
  4. for n in arr:
  5. if n in hm:
  6. hm[n] += 1
  7. else:
  8. hm[n] = 1
  9. count = 0
  10. for key, value in hm.items():
  11. if key + 1 in hm:
  12. count += hm[key]
  13. return count
  14. s = Solution()
  15. print("Expected: 2")
  16. print("Got:", s.countElements([1, 2, 3]))