三刷238. Product of Array Except Self

面经出现 三刷还不会

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

你可能感兴趣的:(三刷238. Product of Array Except Self)