Java 6 lines solution


  • 0
        public int[] productExceptSelf(int[] nums) {
            int res[] = new int[nums.length], left = 1, right = 1;
            for (int i = 0; i < res.length; left *= nums[i++])
                res[i] = left;
            for (int i = res.length - 1; i >= 0; right *= nums[i--])
                res[i] *= right;
            return res;
        }
    

Log in to reply
 

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