Skip to content

Commit 037c6fb

Browse files
committed
Solve 238 with Java.
1 parent 6b1d856 commit 037c6fb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Author: illuz <iilluzen[at]gmail.com>
3+
* File: AC_array_n.java
4+
* Create Date: 2016-02-24 23:23:27
5+
* Descripton:
6+
*/
7+
8+
public static class Solution {
9+
public int[] productExceptSelf(int[] nums) {
10+
if (nums.length == 0) return nums;
11+
int[] left = new int[nums.length];
12+
left[0] = 1;
13+
for (int i = 1; i < nums.length; ++i) {
14+
left[i] = left[i - 1] * nums[i - 1];
15+
}
16+
int right = 1;
17+
for (int i = nums.length - 2; i >= 0; --i) {
18+
right *= nums[i + 1];
19+
left[i] *= right;
20+
}
21+
return left;
22+
}
23+
}

0 commit comments

Comments
 (0)