FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
coding-Interview/SquaresSortedArray.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
/
SquaresSortedArray.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
27 lines (24 loc) · 727 Bytes
Breadcrumbs
coding-Interview
/
SquaresSortedArray.java
Copy path
File metadata and controls
27 lines (24 loc) · 727 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
package
com
.
leetcode
;
public
class
SquaresSortedArray
{
//https://leetcode.com/problems/squares-of-a-sorted-array/
class
Solution
{
public
int
[]
sortedSquares
(
int
[]
nums
) {
int
n
=
nums
.
length
;
int
result
[] =
new
int
[
n
];
int
l
=
0
;
int
r
=
n
-
1
;
int
counter
=
n
-
1
;
while
(
l
<=
r
&&
counter
>=
0
){
if
(
Math
.
abs
(
nums
[
l
])>
Math
.
abs
(
nums
[
r
])){
result
[
counter
] =
nums
[
l
]*
nums
[
l
];
l
++;
}
else
{
result
[
counter
] =
nums
[
r
]*
nums
[
r
];
r
--;
}
counter
--;
}
return
result
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL