Simple Java solution


  • 0
    S
        public int[] productExceptSelf(int[] nums) {
            int n = nums.length, i;
            int[] result = new int[n];
            int cur = 1;
            for (i=0;i<n;i++) {
                result[i] = cur;
                cur *= nums[i];
            }
            cur = 1;
            for (i=n-1;i>=0;i--) {
                result[i] *= cur;
                cur *= nums[i];
            }
            return result;
        }
    }

Log in to reply
 

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