exercicio 1822 resolvido em python
This commit is contained in:
21
1822-sign_of_the_product_of_an_array/python/1822.py
Normal file
21
1822-sign_of_the_product_of_an_array/python/1822.py
Normal 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
|
||||||
Reference in New Issue
Block a user