Skip to content

Commit e168b37

Browse files
committed
[level 1] Title: 같은 숫자는 싫어, Time: 35.69 ms, Memory: 111 MB -BaekjoonHub
1 parent b96c1ab commit e168b37

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# [level 1] 같은 숫자는 싫어 - 12906
2+
3+
[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/12906)
4+
5+
### 성능 요약
6+
7+
메모리: 111 MB, 시간: 35.69 ms
8+
9+
### 구분
10+
11+
코딩테스트 연습 > 스택/큐
12+
13+
### 채점결과
14+
15+
정확성: 71.9<br/>효율성: 28.1<br/>합계: 100.0 / 100.0
16+
17+
### 제출 일자
18+
19+
2025년 08월 18일 14:31:15
20+
21+
### 문제 설명
22+
23+
<p>배열 arr가 주어집니다. 배열 arr의 각 원소는 숫자 0부터 9까지로 이루어져 있습니다. 이때, 배열 arr에서 연속적으로 나타나는 숫자는 하나만 남기고 전부 제거하려고 합니다. 단, 제거된 후 남은 수들을 반환할 때는 배열 arr의 원소들의 순서를 유지해야 합니다. 예를 들면,</p>
24+
25+
<ul>
26+
<li>arr = [1, 1, 3, 3, 0, 1, 1] 이면 [1, 3, 0, 1] 을 return 합니다.</li>
27+
<li>arr = [4, 4, 4, 3, 3] 이면 [4, 3] 을 return 합니다.</li>
28+
</ul>
29+
30+
<p>배열 arr에서 연속적으로 나타나는 숫자는 제거하고 남은 수들을 return 하는 solution 함수를 완성해 주세요.</p>
31+
32+
<h5>제한사항</h5>
33+
34+
<ul>
35+
<li>배열 arr의 크기 : 1,000,000 이하의 자연수</li>
36+
<li>배열 arr의 원소의 크기 : 0보다 크거나 같고 9보다 작거나 같은 정수</li>
37+
</ul>
38+
39+
<hr>
40+
41+
<h5>입출력 예</h5>
42+
<table class="table">
43+
<thead><tr>
44+
<th>arr</th>
45+
<th>answer</th>
46+
</tr>
47+
</thead>
48+
<tbody><tr>
49+
<td>[1,1,3,3,0,1,1]</td>
50+
<td>[1,3,0,1]</td>
51+
</tr>
52+
<tr>
53+
<td>[4,4,4,3,3]</td>
54+
<td>[4,3]</td>
55+
</tr>
56+
</tbody>
57+
</table>
58+
<h5>입출력 예 설명</h5>
59+
60+
<p>입출력 예 #1,2<br>
61+
문제의 예시와 같습니다.</p>
62+
63+
64+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import java.util.*;
2+
3+
public class Solution {
4+
public Stack<Integer> solution(int []arr) {
5+
int[] answer = {};
6+
Stack<Integer> s = new Stack<>();
7+
8+
s.push(arr[0]);
9+
for(int i=1; i<arr.length; i++) {
10+
if(s.peek() != arr[i]) {
11+
s.push(arr[i]);
12+
}
13+
}
14+
15+
return s;
16+
}
17+
}

0 commit comments

Comments
 (0)