# 238. Product of Array Except Self

{% embed url="<https://leetcode.com/problems/product-of-array-except-self/>" %}

三种情况：

1. 完全没有0
2. 有一个0
3. 有多个0

```python
class Solution:
    def productExceptSelf(self, nums: List[int]) -> List[int]:
        zeros = [False for _ in range(len(nums))]
        p = 1
        for i, n in enumerate(nums):
            if not n: zeros[i] = True
            else: p *= n
                
        if zeros.count(True) == 0:
            res = [p//n for n in nums]
        elif zeros.count(True) == 1:
            res = list(map(lambda x: p if zeros[x] else 0, range(len(nums))))
        else:
            res = [0 for _ in range(len(nums))]
            
        return res
```
