# 根据给定数字划分数组
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author yagol
* @date 下午10:43
* @desc the description of this class
**/
class Solution5985 {
public static void main(String[] args) {
System.out.println(Arrays.toString(new Solution5985().pivotArray(
new int[]{-3,2,4,3}, 2
)));
}
public int[] pivotArray(int[] nums, int pivot) {
List<Integer> res = new ArrayList<>();
List<Integer> other = new ArrayList<>();
for (int num : nums) {
if (num < pivot) {
res.add(num);
} else {
other.add(num);
}
}
List<Integer> bigger = new ArrayList<>();
for (Integer integer : other) {
if (integer == pivot) {
res.add(integer);
} else {
bigger.add(integer);
}
}
for (Integer integer : bigger) {
res.add(integer);
}
return res.stream().mapToInt(Integer::valueOf).toArray();
}
}
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
36
37
38
39
40
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
36
37
38
39
40