-
Notifications
You must be signed in to change notification settings - Fork 0
/
SortOutTheMenFromBoys.java
48 lines (41 loc) · 1.17 KB
/
SortOutTheMenFromBoys.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
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.smlnskgmail.jaman.codewarsjava.kyu7;
import java.util.Arrays;
// https://www.codewars.com/kata/5af15a37de4c7f223e00012d
public class SortOutTheMenFromBoys {
private final int[] input;
public SortOutTheMenFromBoys(int[] input) {
this.input = input;
}
public int[] solution() {
int[] boys = Arrays
.stream(input)
.distinct()
.boxed()
.filter(integer -> integer % 2 != 0)
.sorted((o1, o2) -> -Integer.compare(o1, o2))
.mapToInt(value -> value)
.toArray();
int[] men = Arrays
.stream(input)
.distinct()
.filter(value -> value % 2 == 0)
.sorted()
.toArray();
int[] result = new int[men.length + boys.length];
System.arraycopy(
men,
0,
result,
0,
men.length
);
System.arraycopy(
boys,
0,
result,
men.length,
boys.length
);
return result;
}
}