【LeetCode】1822. 数组元素积的符号
时间:2021-04-13 10:19:01
收藏:0
阅读:20
思路:遍历判断每个数的正负
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
评论(0)