Skip to content

Commit 2b8eaa1

Browse files
Create 0905-sort-array-by-parity.java
1 parent 75c3cc5 commit 2b8eaa1

File tree

1 file changed

+19
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)