Sign Of The Product Of The Array | Easy | Efficient

if zero is in array then return 0

class Solution {//1ms
    public int arraySign(int[] nums) {
        int negativeCount = 0;
        for(int n: nums){
            if(n<0)
                negativeCount++;
            if(n==0)
                return 0;
        }
        return (negativeCount%2==0)? 1 : -1;
    }
}
Comments (0)