There was an error while loading. Please reload this page.
1 parent b66fa9f commit 13bdec4Copy full SHA for 13bdec4
238. Product of Array Except Self.py
@@ -0,0 +1,31 @@
1
+class Solution(object):
2
+ def productExceptSelf(self, nums):
3
+ """
4
+ :type nums: List[int]
5
+ :rtype: List[int]
6
7
+
8
+ product = 1
9
+ flag = False
10
+ count = 0
11
+ for i in nums:
12
+ if(i==0):
13
+ flag = True
14
+ count+=1
15
+ if(i!=0):
16
+ product *= i
17
+ arr = []
18
19
+ for i in range(len(nums)):
20
+ if(flag):
21
+ if(nums[i]!=0 or count>1):
22
+ arr.append(0)
23
+ elif(nums[i]==0 and count==1):
24
+ arr.append(product)
25
+ else:
26
+ arr.append(product/nums[i])
27
+ return arr
28
29
30
31
0 commit comments