728x90
728x90
시간초과 이제는 그만 ㅠㅠㅠ!!
import java.util.*;
import java.io.*;
public class Main {
public static void main ( String [] args ) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//수의 개수인 N 을 받아준다 !
int N = Integer.parseInt(br.readLine());
//절대값이 1백만을 넘지않으니 음수까지 고려하여 2백만까지 수용가능하게
//1차원배열을 만들어준다 !
int [] arr = new int [2000001];
//수의 개수만큼 반복하면서 해당 숫자 + 1백만 자리에 1 더하기 !
for(int i = 0; i<N; i++) {
int num = Integer.parseInt(br.readLine()) + 1000000;
arr[num]++;
}
//출력은 StringBuilder로 ! 그냥 0부터 2백만까지돌면서찍으면 시간초과 ㅠ
StringBuilder sb = new StringBuilder();
for(int i = 0; i<2000001; i++) {
if(arr[i] > 0) {
sb.append(i-1000000).append("\n");
}
}
//출력해주면 끝 !
System.out.println(sb);
}
}
728x90
'알고리즘 > 백준' 카테고리의 다른 글
1260 DFS와 BFS (3) | 2023.10.21 |
---|---|
1676 팩토리얼 0의 개수 (2) | 2023.06.06 |
11651 좌표 정렬하기 2 (0) | 2023.05.31 |
10816 숫자 카드 2 (2) | 2023.05.31 |
10773 제로 (0) | 2023.05.31 |