MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / productExceptSelf

Method productExceptSelf

Array/ProductOfArrayExceptSelf.py:44–72  ·  view source on GitHub ↗

:type nums: List[int] :rtype: List[int]

(self, nums)

Source from the content-addressed store, hash-verified

42"""
43class Solution(object):
44 def productExceptSelf(self, nums):
45 """
46 :type nums: List[int]
47 :rtype: List[int]
48 """
49 output = [1]
50 for i in range(len(nums)-1):
51 output.append(output[-1] * nums[i])
52
53 right = 1
54 for i in range(len(nums)-1, -1, -1):
55 output[i] = right * output[i]
56 right *= nums[i]
57
58 return output
59
60 # left = [1]
61 # right = [1]
62
63
64 # for i in range(len(nums)-1):
65 # left.append(left[-1] * nums[i])
66
67 # for i in range(len(nums)-1, 0, -1):
68 # right.append(right[-1] * nums[i])
69
70 # length = len(left)
71
72 # return [left[i] * right[length-1-i] for i in range(length)]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected