Skip to content

Commit 74bb692

Browse files
committed
pes
1 parent 5cbe348 commit 74bb692

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution:
2+
def productExceptSelf(self, nums: List[int]) -> List[int]:
3+
n = len(nums)
4+
answer = [1] * n
5+
left_product = 1
6+
for i in range(n):
7+
answer[i] = left_product
8+
left_product *= nums[i]
9+
right_product = 1
10+
for i in range(n - 1, -1, -1):
11+
answer[i] *= right_product
12+
right_product *= nums[i]
13+
14+
return answer

0 commit comments

Comments
 (0)