File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
product-of-array-except-self Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change 11class Solution :
22 # Space complexity: O(n)
33 # Time complexity: O(n)
4- def _v1 (self , nums : list [int ]) -> list [int ]:
4+ def naive (self , nums : list [int ]) -> list [int ]:
55 prefix = [1 ]
66 for num in nums [:- 1 ]:
77 prefix .append (prefix [- 1 ] * num )
@@ -16,7 +16,7 @@ def _v1(self, nums: list[int]) -> list[int]:
1616
1717 # Space complexity: O(1)
1818 # Time complexity: O(n)
19- def _v2 (self , nums : list [int ]) -> list [int ]:
19+ def with_constant_space (self , nums : list [int ]) -> list [int ]:
2020 n = len (nums )
2121 answer = [1 ] * n
2222
@@ -41,6 +41,6 @@ def productExceptSelf(self, nums: List[int]) -> List[int]:
4141 # 1 -> [0] - [2, 3]
4242 # 2 -> [0, 1] - [3]
4343 # 3 -> [0, 1, 2] -
44- return self ._v2 (nums )
44+ return self .with_constant_space (nums )
4545
4646
You can’t perform that action at this time.
0 commit comments