2215. Find the Difference of Two Arrays
Question
There is a function signFunc(x) that returns:
1ifxis positive.-1ifxis negative.0ifxis equal to0.
You are given an integer array nums. Let product be the product of all values in the array nums.
Return signFunc(product).
Solution
遍历并检查当前元素的正负性,如果为负值则改变符号。
如果为0则返回0。
Code
1 | class Solution { |
2215. Find the Difference of Two Arrays
https://xuanhe95.github.io/2023/05/02/1822-Sign-of-the-Product-of-an-Array/
