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

45 lines
1.3 KiB
HTML

<p>There is a function <code>signFunc(x)</code> that returns:</p>
<ul>
<li><code>1</code> if <code>x</code> is positive.</li>
<li><code>-1</code> if <code>x</code> is negative.</li>
<li><code>0</code> if <code>x</code> is equal to <code>0</code>.</li>
</ul>
<p>You are given an integer array <code>nums</code>. Let <code>product</code> be the product of all values in the array <code>nums</code>.</p>
<p>Return <code>signFunc(product)</code>.</p>
<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input:</strong> nums = [-1,-2,-3,-4,3,2,1]
<strong>Output:</strong> 1
<strong>Explanation:</strong> The product of all values in the array is 144, and signFunc(144) = 1
</pre>
<p><strong>Example 2:</strong></p>
<pre>
<strong>Input:</strong> nums = [1,5,0,2,-3]
<strong>Output:</strong> 0
<strong>Explanation:</strong> The product of all values in the array is 0, and signFunc(0) = 0
</pre>
<p><strong>Example 3:</strong></p>
<pre>
<strong>Input:</strong> nums = [-1,1,-1,1,-1]
<strong>Output:</strong> -1
<strong>Explanation:</strong> The product of all values in the array is -1, and signFunc(-1) = -1
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>-100 &lt;= nums[i] &lt;= 100</code></li>
</ul>