【LeetCode】1822. 数组元素积的符号

思路:遍历判断每个数的正负

class Solution {
public:
    int arraySign(vector<int>& nums) {
        int ans = 1;
        for(auto &n : nums){
            if(n == 0) return 0;
            ans *= (n > 0) ? 1 : -1;
        }
        return ans;
    }
};
原文地址:https://www.cnblogs.com/whisperbb/p/14651280.html