Collections.sort()를 이용하면
ArrayList때문에 메모리 초과가 나더라~!
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
|
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int N = Integer.parseInt(br.readLine());
int[] arr = new int[N];
for(int i=0;i<N;i++){
arr[i]=Integer.parseInt(br.readLine());
}
Arrays.sort(arr);
for(int res : arr){
sb.append(res).append('\n');
}
System.out.println(sb);
}
}
|
cs |