-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy path72.java
More file actions
47 lines (26 loc) · 651 Bytes
/
72.java
File metadata and controls
47 lines (26 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Solution {
public int[] constructArr(int[] a) {
int left[] = new int[a.length];
int right[] = new int[a.length];
int result[] = new int[a.length];
if(a.length==0)
{
return result;
}
left[0] = 1;
right[a.length-1]=1;
for(int i =1;i<a.length;i++)
{
left[i] = left[i-1]*a[i-1];
}
for(int i = a.length-2;i>=0;i--)
{
right[i] = right[i+1]*a[i+1];
}
for(int i=0;i<a.length;i++)
{
result[i] = left[i]*right[i];
}
return result;
}
}