Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def productExceptSelf(nums):
- zero_cnt = 0
- mul = 1
- zero_flag = False
- for num in nums:
- if num != 0:
- mul *= num
- else:
- zero_cnt+=1
- zero_flag = True
- if zero_cnt>1:
- return [0] * len(nums)
- res = []
- if zero_flag==True:
- for num in nums:
- if num==0:
- res.append(mul)
- else:
- res.append(0)
- else:
- for num in nums:
- res.append(int(mul/num))
- return res
Advertisement
Add Comment
Please, Sign In to add comment