java.lang.Object
g1801_1900.s1822_sign_of_the_product_of_an_array.Solution

public class Solution extends Object
1822 - Sign of the Product of an Array.<p>Easy</p> <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><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [-1,-2,-3,-4,3,2,1]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> The product of all values in the array is 144, and signFunc(144) = 1</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,5,0,2,-3]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> The product of all values in the array is 0, and signFunc(0) = 0</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> nums = [-1,1,-1,1,-1]</p> <p><strong>Output:</strong> -1</p> <p><strong>Explanation:</strong> The product of all values in the array is -1, and signFunc(-1) = -1</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 1000</code></li> <li><code>-100 <= nums[i] <= 100</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • arraySign

      public int arraySign(int[] nums)