FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
javaprogram/SortColors.java at master · githubfordipesh/javaprogram · GitHub
githubfordipesh
javaprogram
Repository navigation
Code
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
javaprogram
/
SortColors.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (31 loc) · 750 Bytes
Breadcrumbs
javaprogram
/
SortColors.java
Copy path
File metadata and controls
33 lines (31 loc) · 750 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
32
33
package
com
.
sanket
.
Array
;
/*
Problem Link - https://leetcode.com/problems/sort-colors/
Status - Accepted
*/
public
class
SortColors
{
public
void
sortColors
(
int
[]
nums
) {
int
size
=
nums
.
length
;
int
low
=
0
,
high
=
size
-
1
;
int
i
=
low
;
while
(
i
<=
high
) {
if
(
nums
[
i
] ==
2
) {
swap
(
nums
,
i
,
high
);
high
--;
}
else
if
(
nums
[
i
] ==
0
) {
swap
(
nums
,
i
,
low
);
low
++;
i
++;
}
else
{
i
++;
}
}
}
public
static
void
swap
(
int
[]
arr
,
int
i
,
int
j
) {
int
temp
=
arr
[
j
];
arr
[
j
] =
arr
[
i
];
arr
[
i
] =
temp
;
}
}
Back
|
FazBrowse Home
|
New Git URL