238. Product of Array Except Self

mail@pastecode.io avatar
unknown
plain_text
7 months ago
820 B
14
Indexable
Never
class Solution {
    public int[] productExceptSelf(int[] nums) {
        int lengthOfArray = nums.length;
        int[] answer = new int[lengthOfArray];
        int j = 0;
        for(int k = 0;k < lengthOfArray;k++){
            answer[k] = 1;
        }
       
        
        for(int i = 0;i <= lengthOfArray + 1; i++){
            if(j == i){
                continue;
            }
            else if(j != i && i < lengthOfArray && j < lengthOfArray){
                answer[j] *= nums[i];
                continue;
            }
            else if(i == lengthOfArray){
                continue;
            }
            else if(i == (lengthOfArray + 1)){
                j++;
                i = -1;
                continue;
            }
        }
        return answer;
    }
}