mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
45 lines
1.3 KiB
HTML
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> </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> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= nums.length <= 1000</code></li>
|
|
<li><code>-100 <= nums[i] <= 100</code></li>
|
|
</ul>
|