标签:arrays pre 判断 sig code return for class etc
思路:遍历判断每个数的正负
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;
}
};
标签:arrays pre 判断 sig code return for class etc
原文地址:https://www.cnblogs.com/whisperbb/p/14651280.html