You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>정수 배열 <code>arr</code>가 주어집니다. <code>arr</code>를 이용해 새로운 배열 <code>stk</code>를 만드려고 합니다.</p>
24
+
25
+
<p>변수 <code>i</code>를 만들어 초기값을 0으로 설정한 후 <code>i</code>가 <code>arr</code>의 길이보다 작으면 다음 작업을 반복합니다.</p>
26
+
27
+
<ul>
28
+
<li>만약 <code>stk</code>가 빈 배열이라면 <code>arr[i]</code>를 <code>stk</code>에 추가하고 <code>i</code>에 1을 더합니다.</li>
29
+
<li><code>stk</code>에 원소가 있고, <code>stk</code>의 마지막 원소가 <code>arr[i]</code>보다 작으면 <code>arr[i]</code>를 <code>stk</code>의 뒤에 추가하고 <code>i</code>에 1을 더합니다.</li>
30
+
<li><code>stk</code>에 원소가 있는데 <code>stk</code>의 마지막 원소가 <code>arr[i]</code>보다 크거나 같으면 <code>stk</code>의 마지막 원소를 <code>stk</code>에서 제거합니다.</li>
31
+
</ul>
32
+
33
+
<p>위 작업을 마친 후 만들어진 <code>stk</code>를 return 하는 solution 함수를 완성해 주세요.</p>
34
+
35
+
<hr>
36
+
37
+
<h5>제한사항</h5>
38
+
39
+
<ul>
40
+
<li>1 ≤ <code>arr</code>의 길이 ≤ 100,000
41
+
42
+
<ul>
43
+
<li>1 ≤ <code>arr</code>의 원소 ≤ 100,000</li>
44
+
</ul></li>
45
+
</ul>
46
+
47
+
<hr>
48
+
49
+
<h5>입출력 예</h5>
50
+
<tableclass="table">
51
+
<thead><tr>
52
+
<th>arr</th>
53
+
<th>result</th>
54
+
</tr>
55
+
</thead>
56
+
<tbody><tr>
57
+
<td>[1, 4, 2, 5, 3]</td>
58
+
<td>[1, 2, 3]</td>
59
+
</tr>
60
+
</tbody>
61
+
</table>
62
+
<hr>
63
+
64
+
<h5>입출력 예 설명</h5>
65
+
66
+
<p>입출력 예 #1</p>
67
+
68
+
<ul>
69
+
<li>각 작업을 마친 후에 배열의 변화를 나타내면 다음 표와 같습니다.</li>
70
+
</ul>
71
+
<tableclass="table">
72
+
<thead><tr>
73
+
<th>i</th>
74
+
<th>arr[i]</th>
75
+
<th>stk</th>
76
+
</tr>
77
+
</thead>
78
+
<tbody><tr>
79
+
<td>0</td>
80
+
<td>1</td>
81
+
<td>[]</td>
82
+
</tr>
83
+
<tr>
84
+
<td>1</td>
85
+
<td>4</td>
86
+
<td>[1]</td>
87
+
</tr>
88
+
<tr>
89
+
<td>2</td>
90
+
<td>2</td>
91
+
<td>[1, 4]</td>
92
+
</tr>
93
+
<tr>
94
+
<td>2</td>
95
+
<td>2</td>
96
+
<td>[1]</td>
97
+
</tr>
98
+
<tr>
99
+
<td>3</td>
100
+
<td>5</td>
101
+
<td>[1, 2]</td>
102
+
</tr>
103
+
<tr>
104
+
<td>4</td>
105
+
<td>3</td>
106
+
<td>[1, 2, 5]</td>
107
+
</tr>
108
+
<tr>
109
+
<td>4</td>
110
+
<td>3</td>
111
+
<td>[1, 2]</td>
112
+
</tr>
113
+
<tr>
114
+
<td>-</td>
115
+
<td>-</td>
116
+
<td>[1, 2, 3]</td>
117
+
</tr>
118
+
</tbody>
119
+
</table>
120
+
<ul>
121
+
<li>따라서 [1, 2, 3]을 return 합니다.</li>
122
+
</ul>
123
+
124
+
125
+
> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges
0 commit comments