Created
March 28, 2021 21:45
-
-
Save mvallebr/91c934fe76185e14eb425a921f1b18c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| class Solution: | |
| def productExceptSelf(self, nums: List[int]) -> List[int]: | |
| result = [0] * len(nums) | |
| product = 1 | |
| for i in range(len(nums) -1, -1, -1): | |
| product *= nums[i] | |
| result[i] = product | |
| product = 1 | |
| for i in range(len(nums)): | |
| next_one = result[i+1] if i < len(result)-1 else 1 | |
| result[i] = product * next_one | |
| product *= nums[i] | |
| return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment