My very easy-uderstanding Solution


  • -1
    E
    		int totalPro = 1;int zero = 0;
    		for(int i=0;i<nums.length;i++){
    			if(nums[i] != 0) totalPro *= nums[i];
    			else{
    				zero += 1;
    			}
    		}
    		
    		int[] result = new int[nums.length];
    		if(zero == nums.length) return result;
    		for(int i=0;i<result.length;i++){
    			if(nums[i] != 0 && zero > 0) result[i] = 0;
    			else if(nums[i] != 0 && zero == 0) result[i] = totalPro / nums[i];
    			else if(nums[i] == 0 && zero >1) result[i] = 0;
    			else if(nums[i] == 0 && zero <=1) result[i] = totalPro; 
    		}
    		return result;

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.