1822. Sign of the Product of an Array Easy
1/**
2 * [1822] Sign of the Product of an Array
3 *
4 * There is a function signFunc(x) that returns:
5 *
6 * 1 if x is positive.
7 * -1 if x is negative.
8 * 0 if x is equal to 0.
9 *
10 * You are given an integer array nums. Let product be the product of all values in the array nums.
11 * Return signFunc(product).
12 *
13 * Example 1:
14 *
15 * Input: nums = [-1,-2,-3,-4,3,2,1]
16 * Output: 1
17 * Explanation: The product of all values in the array is 144, and signFunc(144) = 1
18 *
19 * Example 2:
20 *
21 * Input: nums = [1,5,0,2,-3]
22 * Output: 0
23 * Explanation: The product of all values in the array is 0, and signFunc(0) = 0
24 *
25 * Example 3:
26 *
27 * Input: nums = [-1,1,-1,1,-1]
28 * Output: -1
29 * Explanation: The product of all values in the array is -1, and signFunc(-1) = -1
30 *
31 *
32 * Constraints:
33 *
34 * 1 <= nums.length <= 1000
35 * -100 <= nums[i] <= 100
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/sign-of-the-product-of-an-array/
41// discuss: https://leetcode.com/problems/sign-of-the-product-of-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn array_sign(nums: Vec<i32>) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_1822() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.