Java solution 90ms


  • 0
    M
    public int[] productExceptSelf(int[] nums) {
    	int[] rs = new int[nums.length];
    	if (nums.length <= 1) {
    		return rs;
    	}
    	rs[0] = nums[1];
    	rs[1] = nums[0];
    	for (int i = 2; i < nums.length; i++) {
    		rs[i] = rs[i-1] * nums[i-1];
    		for(int j=0; j<i; j++){
    			rs[j] *= nums[i];
    		}
    	}
    	return rs;
    }

  • 0
    B

    This solution use O(n^2) time complexity


Log in to reply
 

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