Skip to content

Commit 5628de6

Browse files
authored
Create product_of_array_except_self.py
1 parent 0b554b9 commit 5628de6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

product_of_array_except_self.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def product_except_self(nums):
2+
n = len(nums)
3+
result = [1] * n
4+
5+
for i in range(n):
6+
for j in range(n):
7+
if i != j:
8+
result[i] *= nums[j]
9+
10+
return result
11+
12+
# Test the function with the example input
13+
print(product_except_self([1, 2, 3, 4])) # Output: [24, 12, 8, 6]

0 commit comments

Comments
 (0)