From 3d3b9a3fcb466f9557ebf5c6dfaeed4f1eac1458 Mon Sep 17 00:00:00 2001 From: Luis Rodrigues Date: Wed, 12 Feb 2025 18:11:08 +0000 Subject: [PATCH] exercicio 1822 resolvido em python --- .../python/1822.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 1822-sign_of_the_product_of_an_array/python/1822.py diff --git a/1822-sign_of_the_product_of_an_array/python/1822.py b/1822-sign_of_the_product_of_an_array/python/1822.py new file mode 100644 index 0000000..4c06e8f --- /dev/null +++ b/1822-sign_of_the_product_of_an_array/python/1822.py @@ -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