Leetcode in Java && Oracle
image_2021-11-30_11-05-51.png
image_2021-11-30_11-30-57.png
25.8 KB
#python
#N1822. Sign of the Product of an Array
#anotherSolution
#N1822. Sign of the Product of an Array
#anotherSolution
class Solution:
def arraySign(self, nums: List[int]) -> int:
counter = 0
for i in nums:
if i == 0:
return 0
if i < 0:
counter +=1
return 1 if counter % 2 == 0 else -1