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 8cf16ca commit 6daf4f8Copy full SHA for 6daf4f8
Two Pointers/Meeting/Array/productExceptSelf.java
@@ -0,0 +1,28 @@
1
+class Solution {
2
+ public int[] productExceptSelf(int[] nums) {
3
+ int[] left = new int[nums.length];
4
+ int[] right = new int[nums.length];
5
+ int prod = 1;
6
+ for (int i=0; i<nums.length; i++) {
7
+ if (i >= 1) {
8
+ prod = prod*nums[i-1];
9
+ }
10
+ left[i] = prod;
11
12
+
13
14
+ int p = 1;
15
+ for (int i=nums.length - 1; i>=0; i--) {
16
+ if (i < nums.length - 1) {
17
+ p = p*nums[i+1];
18
19
+ right[i] = p;
20
21
22
+ for (int i = 0; i< nums.length; i++) {
23
+ nums[i] = left[i]*right[i];
24
25
26
+ return nums;
27
28
+}
0 commit comments