Return the Sign of an Array's Product. For the product of all integers in nums, return 1 when it is positive, -1 when negative, or 0 when zero. The full product does not need to be constructed.
### Problem
For the product of all integers in `nums`, return 1 when it is positive, -1 when negative, or 0 when zero. The full product does not need to be constructed.
```cpp
class Solution {
public:
int arraySign(vector<int>& nums);
};
```
### Examples
**Example 1:**
```text
nums = [-4,2,-3]
Output: 1
Explanation: Two negative factors yield a positive product.
```
**Example 2:**
```text
nums = [7,-2,0,-5]
Output: 0
Explanation: One zero factor makes the whole product zero.
```
### Constraints
- `1 <= nums.length <= 1000`.
- Each entry lies in `[-100,100]`.
### Clarifying Questions
The source describes signFunc to define the requested result; the provided public callable is arraySign and returns only the product’s sign.
```hint Inspect the structure
What are the three permitted return values, including the case of a zero factor?
```
### Reasoning checkpoints
- Justify the returned sign for zero, positive, and negative products.
- Keep arithmetic valid even when the product's magnitude cannot fit a fixed-width integer.
### Optional extensions
How would you obtain the sign of a product supplied as a stream?
Overview: Return the Sign of an Array's Product. For the product of all integers in nums, return 1 when it is positive, -1 when negative, or 0 when zero. The full product does not need to be constructed.
For the product of all integers in nums, return 1 when it is positive, -1 when negative, or 0 when zero. The full product does not need to be constructed.
class Solution {
public:
int arraySign(vector<int>& nums);
};
Examples
Example 1:
nums = [-4,2,-3]
Output: 1
Explanation: Two negative factors yield a positive product.
Example 2:
nums = [7,-2,0,-5]
Output: 0
Explanation: One zero factor makes the whole product zero.
Constraints
1 <= nums.length <= 1000
.
Each entry lies in
[-100,100]
.
Clarifying Questions Guidance
The source describes signFunc to define the requested result; the provided public callable is arraySign and returns only the product’s sign.
Reasoning checkpoints
Justify the returned sign for zero, positive, and negative products.
Keep arithmetic valid even when the product's magnitude cannot fit a fixed-width integer.
Optional extensions
How would you obtain the sign of a product supplied as a stream?