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.

12345678910111213141516171819202122
  1. class Solution:
  2. def productExceptSelf(self, nums):
  3. left = [1]
  4. right = [1]
  5. for x in range(1, len(nums)):
  6. left.append(left[x-1] * nums[x-1])
  7. for x in range(1, len(nums)):
  8. right.append(1)
  9. for x in range(len(nums) - 2, -1, -1):
  10. right[x] = right[x+1] * nums[x+1]
  11. result = []
  12. for x in range(0, len(left)):
  13. result.append(left[x] * right[x])
  14. return result
  15. s = Solution()
  16. print("Expected: [24, 12, 8, 6]")
  17. print("Got:", s.productExceptSelf([1, 2, 3, 4]))