力扣 1822. 数组元素积的符号

解法

1
2
3
4
5
6
7
8
def arraySign(nums):
count = 0
for num in nums:
if num < 0:
count += 1
elif num == 0:
return 0
return 1 if count % 2 == 0 else -1
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022 eightyninth
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信