algorithm
2751 - 수 정렬하기 2
tonirr
2020. 5. 11. 07:16
- 시간초과가 나지않게 푸는것이 핵심이다. 처음에는 Scanner로 입력받아서 계속 시간초과가 났었는데 BufferedReader로 받으니 시간초과가 나지 않았다.
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
ArrayList<Integer> list = new ArrayList<Integer>();
for(int i = 1; i <= n; i++) {
list.add(Integer.parseInt(br.readLine()));
}
Collections.sort(list);
for(int i: list)
System.out.println(i);
}
}