Description
Given an integer array nums, let product be the product of all values. Return 1 if product is positive, -1 if negative, and 0 if equal to 0.
Examples
Input:
nums = [-1,-2,-3,-4,3,2,1]Output:
1Explanation:
Product is positive.
Input:
nums = [1,5,0,2,-3]Output:
0Explanation:
The array contains 0, so the sign of the product is 0 regardless of other elements.
Input:
nums = [-1,1,-1,1,-1]Output:
-1Explanation:
There are three negative numbers, so the product is negative. The sign function returns -1.
Constraints
- •
1 ≤ nums.length ≤ 1000