FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
coding-Interview/ProductArrayExceptSelf.java at master · arjunmullick/coding-Interview · GitHub
arjunmullick
/
coding-Interview
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
3
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
coding-Interview
/
ProductArrayExceptSelf.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (25 loc) · 772 Bytes
Breadcrumbs
coding-Interview
/
ProductArrayExceptSelf.java
Copy path
File metadata and controls
31 lines (25 loc) · 772 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
com
.
leetcode
;
public
class
ProductArrayExceptSelf
{
//https://leetcode.com/problems/product-of-array-except-self/
class
Solution
{
public
int
[]
productExceptSelf
(
int
[]
nums
) {
int
n
=
nums
.
length
;
if
(
n
<=
1
)
return
nums
;
int
[]
L
=
new
int
[
n
];
int
[]
R
=
new
int
[
n
];
L
[
0
] =
1
;
for
(
int
i
=
1
;
i
<
n
;
i
++){
L
[
i
] =
L
[
i
-
1
] *
nums
[
i
-
1
];
}
R
[
n
-
1
] =
1
;
for
(
int
i
=
n
-
2
;
i
>=
0
;
i
--){
R
[
i
] =
R
[
i
+
1
]*
nums
[
i
+
1
];
}
int
result
[] =
new
int
[
n
];
for
(
int
i
=
0
;
i
<
n
;
i
++){
result
[
i
] =
L
[
i
] *
R
[
i
];
}
return
result
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL