Skip to content

Commit 065fdd0

Browse files
committed
product of array Except self solved
1 parent 5947aa6 commit 065fdd0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public int[] productExceptSelf(int[] nums) {
3+
int[] answer = new int[nums.length];
4+
int multi = nums[0];
5+
answer[0] = 1;
6+
7+
for(int i = 1; i < nums.length; i++){
8+
answer[i] = multi;
9+
multi *= nums[i];
10+
}
11+
12+
multi = nums[nums.length-1];
13+
for(int i = nums.length-2; i >= 0; i--){
14+
answer[i] *= multi;
15+
multi *= nums[i];
16+
}
17+
18+
return answer;
19+
}
20+
}
21+

0 commit comments

Comments
 (0)