My LeetCode grinding. Trying to do a problem a day.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425
  1. class Solution:
  2. def sumZero(self, n):
  3. # two cases: even and odd
  4. result = []
  5. count = 1
  6. neg = True
  7. # this ensure the odd case works
  8. if n % 2 != 0:
  9. result.append(0)
  10. while len(result) != n:
  11. if neg:
  12. result.append(-count)
  13. neg = False
  14. else:
  15. result.append(count)
  16. count += 1
  17. neg = True
  18. return result
  19. s = Solution()
  20. print("Expected: 0")
  21. print("Got:", str(sum(s.sumZero(32))))