Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

1822. Sign of the Product of an Array leetcode

class Solution {
public:
    int arraySign(vector<int>& nums) {
        long long sum=1;
        for(int i=0;i<nums.size();i++)
        {
            if(nums[i]>0)
                nums[i]=1;
            else if(nums[i]<0)
                nums[i]=-1;
            else
                nums[i]=0;
            sum*=nums[i];
        }
        return sum;
    }
};
Source by codejudge.blogspot.com #
 
PREVIOUS NEXT
Tagged: #Sign #Product #Array #leetcode
ADD COMMENT
Topic
Name
8+9 =