- 
                Notifications
    
You must be signed in to change notification settings  - Fork 93
 
Open
Description
출력시에 System.out.println(x) 로 하나씩 출력하는게 아니라
StringBuilder 를 사용해서 한번에 출력하면 시간초과를 피할 수 있습니다.
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        ArrayList<Integer> data = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int x = Integer.parseInt(br.readLine());
            data.add(x);
        }
        Collections.sort(data);
        StringBuilder sb = new StringBuilder();
        for (int x: data) {
            sb.append(x).append("\n");
        }
        System.out.println(sb);
        br.close();
    }
}Metadata
Metadata
Assignees
Labels
No labels