forked from alexprut/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
37 lines (32 loc) · 1.03 KB
/
Solution.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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
ArrayList<Integer> left = new ArrayList<Integer>();
ArrayList<Integer> equal = new ArrayList<Integer>();
ArrayList<Integer> right = new ArrayList<Integer>();
int pivot = sc.nextInt();
equal.add(pivot);
for (int i = 1; i < n; i++) {
int tmp = sc.nextInt();
if (pivot == tmp) {
equal.add(tmp);
} else if (tmp < pivot) {
left.add(tmp);
} else {
right.add(tmp);
}
}
for (int i = 0; i < left.size(); i++) {
System.out.print(left.get(i) + " ");
}
for (int i = 0; i < equal.size(); i++) {
System.out.print(equal.get(i) + " ");
}
for (int i = right.size() - 1; i >= 0; i--) {
System.out.print(right.get(i) + " ");
}
}
}