1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/数组元素积的符号 [sign-of-the-product-of-an-array].html
2022-03-29 12:43:11 +08:00

47 lines
1.3 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>已知函数 <code>signFunc(x)</code> 将会根据 <code>x</code> 的正负返回特定值:</p>
<ul>
<li>如果 <code>x</code> 是正数,返回 <code>1</code></li>
<li>如果 <code>x</code> 是负数,返回 <code>-1</code></li>
<li>如果 <code>x</code> 是等于 <code>0</code> ,返回 <code>0</code></li>
</ul>
<p>给你一个整数数组 <code>nums</code> 。令 <code>product</code> 为数组 <code>nums</code> 中所有元素值的乘积。</p>
<p>返回 <code>signFunc(product)</code></p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [-1,-2,-3,-4,3,2,1]
<strong>输出:</strong>1
<strong>解释:</strong>数组中所有值的乘积是 144 ,且 signFunc(144) = 1
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,5,0,2,-3]
<strong>输出:</strong>0
<strong>解释:</strong>数组中所有值的乘积是 0 ,且 signFunc(0) = 0
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>nums = [-1,1,-1,1,-1]
<strong>输出:</strong>-1
<strong>解释:</strong>数组中所有值的乘积是 -1 ,且 signFunc(-1) = -1
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= nums.length <= 1000</code></li>
<li><code>-100 <= nums[i] <= 100</code></li>
</ul>