Sign of the Product of an Array

Easy

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:1
Explanation:

Product is positive.

Input:nums = [1,5,0,2,-3]
Output:0
Explanation:

The array contains 0, so the sign of the product is 0 regardless of other elements.

Input:nums = [-1,1,-1,1,-1]
Output:-1
Explanation:

There are three negative numbers, so the product is negative. The sign function returns -1.

Constraints

  • 1 ≤ nums.length ≤ 1000

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!