We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 356bfbb commit 4306525Copy full SHA for 4306525
product-of-array-except-self/changhyumm.py
@@ -0,0 +1,22 @@
1
+class Solution:
2
+ def productExceptSelf(self, nums: List[int]) -> List[int]:
3
+ # ans = [1] * len(nums)
4
+ # for i in range(len(nums)):
5
+ # for j in range(len(nums)):
6
+ # if i != j:
7
+ # ans[i] = ans[i] * nums[j]
8
+ # return ans
9
+ # 시간복잡도를 줄이기 위해서 이중루프를 안쓰는 방법으로
10
+ left = [1] * len(nums)
11
+ right = [1] * len(nums)
12
+ for i in range(len(nums) - 1):
13
+ left[i+1] = left[i] * nums[i]
14
+ print(left)
15
+ for j in range(len(nums) - 1, 0, -1):
16
+ right[j-1] = right[j] * nums[j]
17
+ print(right)
18
+
19
+ answer = []
20
+ for k in range(len(left)):
21
+ answer.append(left[k]*right[k])
22
+ return answer
0 commit comments