Skip to content

Commit 1f1ae4c

Browse files
authored
Create Sort Array By Parity
1 parent bb7630c commit 1f1ae4c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sort Array By Parity

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public int[] sortArrayByParity(int[] A) {
3+
int count1 = 0;
4+
int count2 = A.length-1;
5+
int[] res = new int[A.length];
6+
for(int i : A){
7+
if(i % 2 == 0){
8+
res[count1++] = i;
9+
}
10+
else{
11+
res[count2--] = i;
12+
}
13+
}
14+
return res;
15+
}
16+
}

0 commit comments

Comments
 (0)