Page tree
Skip to end of metadata
Go to start of metadata

OTL... sorry to check the solution....

    public int[] productExceptSelf(int[] nums) {
        
        int length = nums.length;
        int[] answer = new int[length];
        answer[0] = 1;
        for (int i = 1; i < length; i++) {
            answer[i] = nums[i-1] * answer[i-1];
        }

        int value = 1;
        for (int i = length - 1; i>=0; i--) {
            answer[i] = answer[i] * value;
            value *= nums[i];
        }
        return answer;
    }
  • No labels