-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_0905.java
More file actions
29 lines (28 loc) · 888 Bytes
/
_0905.java
File metadata and controls
29 lines (28 loc) · 888 Bytes
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
package com.github.aditya;
public class _0905 {
// 1 ms, faster than 96.63%, memory 43 MB, less than 91.80%
class Solution {
public int[] sortArrayByParity(int[] nums) {
int left = 0, right = nums.length - 1;
while (left <= right) {
int i = nums[left] % 2;
int j = nums[right] % 2;
if (i == 1 && j == 0) {
int temp = nums[left];
nums[left] = nums[right];
nums[right] = temp;
left++;
right--;
} else if (i == 0 && j == 0) {
left++;
} else if (i == 1 && j == 1) {
right--;
} else {
left++;
right--;
}
}
return nums;
}
}
}