-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathSort 0 1.java
35 lines (33 loc) · 850 Bytes
/
Sort 0 1.java
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
public class Solution {
public static void sortZeroesAndOne(int[] arr) {
int i =0;
int j = arr.length-1 ;
while(i < j)
{
if(arr[i] == 0 && arr[j] == 1)
{
i++ ; j-- ; continue ;
}
else{
if(arr[i] == 0 && arr[j] == 0)
{
i++ ; continue ;
}
else if(arr[i] == 1 && arr[j] == 1)
{
j-- ; continue ;
}
else if(arr[i] == 0 && arr[j] == 1)
{
i++ ; j-- ; continue ;
}
else{
int temp =arr[i] ;
arr[i] = arr[j] ;
arr[j] = temp ;
i++ ; j-- ;
}
}
}
}
}