Skip to content

Commit 0401aee

Browse files
committed
[level 0] Title: 문자열 정렬하기 (1), Time: 0.06 ms, Memory: 77.2 MB -BaekjoonHub
1 parent 55df41c commit 0401aee

2 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# [level 0] 문자열 정렬하기 (1) - 120850
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/120850)
4+
5+
### 성능 요약
6+
7+
메모리: 77.2 MB, 시간: 0.06 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 코딩테스트 입문
12+
13+
### 채점결과
14+
15+
정확성: 100.0<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2026년 05월 07일 17:19:24
20+
21+
### 문제 설명
22+
23+
<p>문자열 <code>my_string</code>이 매개변수로 주어질 때, <code>my_string</code> 안에 있는 숫자만 골라 오름차순 정렬한 리스트를&nbsp;return 하도록 solution 함수를 작성해보세요.</p>
24+
25+
<hr>
26+
27+
<h5>제한사항</h5>
28+
29+
<ul>
30+
<li>1 ≤ <code>my_string</code>의 길이 ≤ 100</li>
31+
<li><code>my_string</code>에는 숫자가 한 개 이상 포함되어 있습니다.</li>
32+
<li><code>my_string</code>은 영어 소문자 또는 0부터 9까지의 숫자로 이루어져 있습니다.
33+
- - -</li>
34+
</ul>
35+
36+
<h5>입출력 예</h5>
37+
<table class="table">
38+
<thead><tr>
39+
<th>my_string</th>
40+
<th>result</th>
41+
</tr>
42+
</thead>
43+
<tbody><tr>
44+
<td>"hi12392"</td>
45+
<td>[1, 2, 2, 3, 9]</td>
46+
</tr>
47+
<tr>
48+
<td>"p2o4i8gj2"</td>
49+
<td>[2, 2, 4, 8]</td>
50+
</tr>
51+
<tr>
52+
<td>"abcde0"</td>
53+
<td>[0]</td>
54+
</tr>
55+
</tbody>
56+
</table>
57+
<hr>
58+
59+
<h5>입출력 예 설명</h5>
60+
61+
<p>입출력 예 #1</p>
62+
63+
<ul>
64+
<li>"hi12392"에 있는 숫자 1, 2, 3, 9, 2를 오름차순 정렬한 [1, 2, 2, 3, 9]를 return 합니다.</li>
65+
</ul>
66+
67+
<p>입출력 예 #2</p>
68+
69+
<ul>
70+
<li>"p2o4i8gj2"에 있는 숫자 2, 4, 8, 2를 오름차순 정렬한 [2, 2, 4, 8]을 return 합니다.</li>
71+
</ul>
72+
73+
<p>입출력 예 #3</p>
74+
75+
<ul>
76+
<li>"abcde0"에 있는 숫자 0을 오름차순 정렬한 [0]을 return 합니다.</li>
77+
</ul>
78+
79+
80+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
public int[] solution(String my_string) {
5+
List<Integer> list = new ArrayList<>();
6+
7+
for(int i=0; i<my_string.length(); i++){
8+
char c = my_string.charAt(i);
9+
10+
if(c >= '0' && c <= '9'){
11+
list.add(c-'0');
12+
}
13+
else continue;
14+
}
15+
16+
Collections.sort(list);
17+
18+
int [] answer = new int[list.size()];
19+
20+
for(int i=0; i<list.size(); i++){
21+
answer[i] = list.get(i);
22+
}
23+
24+
25+
return answer;
26+
}
27+
}

0 commit comments

Comments
 (0)