We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9666671 commit b9dce6aCopy full SHA for b9dce6a
product-of-array-except-self/Lyla-Dev.java
@@ -0,0 +1,26 @@
1
+class Solution {
2
+ public int[] productExceptSelf(int[] nums) {
3
+ int[] answer = new int[nums.length];
4
+ int[] front = new int[nums.length];
5
+ int[] back = new int[nums.length];
6
+
7
+ for (int i = 0; i < nums.length; i++) {
8
+ front[i] = 1;
9
+ back[i] = 1;
10
+ }
11
12
+ for (int i = 0; i < nums.length - 1; i++) {
13
+ front[i + 1] = front[i] * nums[i];
14
15
16
+ for (int i = nums.length - 1; i > 0; i--) {
17
+ back[i - 1] = nums[i] * back[i];
18
19
20
21
+ answer[i] = front[i] * back[i];
22
23
24
+ return answer;
25
26
+}
0 commit comments