exercicio 1822 resolvido em python

This commit is contained in:
2025-02-12 18:11:08 +00:00
parent c25cd97ea1
commit 3d3b9a3fcb

View File

@ -0,0 +1,21 @@
# 1822. Sign of the Product of an Array
#
# Implement a function signFunc(x) that returns:
#
# 1 if x is positive.
# -1 if x is negative.
# 0 if x is equal to 0.
#
# You are given an integer array nums. Let product be the product of all
# values in the array nums.
#
# Return signFunc(product)
def arraySign(nums: list[int]) -> int:
resultado: int = 1
for value in nums:
if value == 0:
return 0
resultado *= value
return 1 if resultado > 0 else -1