문졔 : 수 정렬하기 3
시간 제한 : 3 sec
메모리 제한 : 8MB
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
|
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int[] count = new int[10001];
int n = Integer.parseInt(br.readLine());
Arrays.fill(count, 0);
for (int i = 0; i < n; i++) {
count[Integer.parseInt(br.readLine())]++;
}
for (int i = 1; i <= 10000; i++) {
if(count[i]!=0)
for (int j = 0; j < count[i]; j++) {
bw.write(Integer.toString(i));
bw.newLine();
}
}
bw.flush();
br.close();
bw.close();
}
}
|
cs |
정렬해야하는 수 값의 범위가 작다면 계수 정렬 고려해볼 것!
시간 복잡도가 O(N)이다.
'algorithm > 문제 풀이' 카테고리의 다른 글
99클럽 코테 스터디 4일차 TIL - 프로그래머스 문제 : 할인 행사 (1) | 2024.04.04 |
---|---|
99클럽 코테 스터디 2일차 TIL - 백준 11279 (최대 힙) java (0) | 2024.04.02 |
백준 2740번 (행렬 곱셈) 자바 Java11 (0) | 2021.01.26 |
백준 1914번 (하노이 탑) 자바 Java11 (0) | 2021.01.26 |
백준 2747번 (피보나치 수) 자바 Java 11 (0) | 2021.01.23 |