1822. Sign of the Product of an Array

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1822

class Solution:
    def arraySign(self, nums: List[int]) -> int:
        res = 1
        for v in nums:
            if v == 0:
                return 0
            if v < 0:
                res *= -1
        return res