|
| 1 | +# [level 2] 이진 변환 반복하기 - 70129 |
| 2 | + |
| 3 | +[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/70129) |
| 4 | + |
| 5 | +### 성능 요약 |
| 6 | + |
| 7 | +메모리: 39.4 MB, 시간: 8.96 ms |
| 8 | + |
| 9 | +### 구분 |
| 10 | + |
| 11 | +코딩테스트 연습 > 월간 코드 챌린지 시즌1 |
| 12 | + |
| 13 | +### 채점결과 |
| 14 | + |
| 15 | +정확성: 100.0<br/>합계: 100.0 / 100.0 |
| 16 | + |
| 17 | +### 제출 일자 |
| 18 | + |
| 19 | +2025년 07월 23일 11:29:19 |
| 20 | + |
| 21 | +### 문제 설명 |
| 22 | + |
| 23 | +<p>0과 1로 이루어진 어떤 문자열 x에 대한 이진 변환을 다음과 같이 정의합니다.</p> |
| 24 | + |
| 25 | +<ol> |
| 26 | +<li>x의 모든 0을 제거합니다.</li> |
| 27 | +<li>x의 길이를 c라고 하면, x를 "c를 2진법으로 표현한 문자열"로 바꿉니다.</li> |
| 28 | +</ol> |
| 29 | + |
| 30 | +<p>예를 들어, <code>x = "0111010"</code>이라면, x에 이진 변환을 가하면 <code>x = "0111010" -> "1111" -> "100"</code> 이 됩니다.</p> |
| 31 | + |
| 32 | +<p>0과 1로 이루어진 문자열 s가 매개변수로 주어집니다. s가 "1"이 될 때까지 계속해서 s에 이진 변환을 가했을 때, 이진 변환의 횟수와 변환 과정에서 제거된 모든 0의 개수를 각각 배열에 담아 return 하도록 solution 함수를 완성해주세요.</p> |
| 33 | + |
| 34 | +<hr> |
| 35 | + |
| 36 | +<h5>제한사항</h5> |
| 37 | + |
| 38 | +<ul> |
| 39 | +<li>s의 길이는 1 이상 150,000 이하입니다.</li> |
| 40 | +<li>s에는 '1'이 최소 하나 이상 포함되어 있습니다.</li> |
| 41 | +</ul> |
| 42 | + |
| 43 | +<hr> |
| 44 | + |
| 45 | +<h5>입출력 예</h5> |
| 46 | +<table class="table"> |
| 47 | + <thead><tr> |
| 48 | +<th>s</th> |
| 49 | +<th>result</th> |
| 50 | +</tr> |
| 51 | +</thead> |
| 52 | + <tbody><tr> |
| 53 | +<td><code>"110010101001"</code></td> |
| 54 | +<td><code>[3,8]</code></td> |
| 55 | +</tr> |
| 56 | +<tr> |
| 57 | +<td><code>"01110"</code></td> |
| 58 | +<td><code>[3,3]</code></td> |
| 59 | +</tr> |
| 60 | +<tr> |
| 61 | +<td><code>"1111111"</code></td> |
| 62 | +<td><code>[4,1]</code></td> |
| 63 | +</tr> |
| 64 | +</tbody> |
| 65 | + </table> |
| 66 | +<hr> |
| 67 | + |
| 68 | +<h5>입출력 예 설명</h5> |
| 69 | + |
| 70 | +<p>입출력 예 #1</p> |
| 71 | + |
| 72 | +<ul> |
| 73 | +<li>"110010101001"이 "1"이 될 때까지 이진 변환을 가하는 과정은 다음과 같습니다.</li> |
| 74 | +</ul> |
| 75 | +<table class="table"> |
| 76 | + <thead><tr> |
| 77 | +<th>회차</th> |
| 78 | +<th>이진 변환 이전</th> |
| 79 | +<th>제거할 0의 개수</th> |
| 80 | +<th>0 제거 후 길이</th> |
| 81 | +<th>이진 변환 결과</th> |
| 82 | +</tr> |
| 83 | +</thead> |
| 84 | + <tbody><tr> |
| 85 | +<td>1</td> |
| 86 | +<td>"110010101001"</td> |
| 87 | +<td>6</td> |
| 88 | +<td>6</td> |
| 89 | +<td>"110"</td> |
| 90 | +</tr> |
| 91 | +<tr> |
| 92 | +<td>2</td> |
| 93 | +<td>"110"</td> |
| 94 | +<td>1</td> |
| 95 | +<td>2</td> |
| 96 | +<td>"10"</td> |
| 97 | +</tr> |
| 98 | +<tr> |
| 99 | +<td>3</td> |
| 100 | +<td>"10"</td> |
| 101 | +<td>1</td> |
| 102 | +<td>1</td> |
| 103 | +<td>"1"</td> |
| 104 | +</tr> |
| 105 | +</tbody> |
| 106 | + </table> |
| 107 | +<ul> |
| 108 | +<li>3번의 이진 변환을 하는 동안 8개의 0을 제거했으므로, <code>[3,8]</code>을 return 해야 합니다.</li> |
| 109 | +</ul> |
| 110 | + |
| 111 | +<p>입출력 예 #2</p> |
| 112 | + |
| 113 | +<ul> |
| 114 | +<li>"01110"이 "1"이 될 때까지 이진 변환을 가하는 과정은 다음과 같습니다.</li> |
| 115 | +</ul> |
| 116 | +<table class="table"> |
| 117 | + <thead><tr> |
| 118 | +<th>회차</th> |
| 119 | +<th>이진 변환 이전</th> |
| 120 | +<th>제거할 0의 개수</th> |
| 121 | +<th>0 제거 후 길이</th> |
| 122 | +<th>이진 변환 결과</th> |
| 123 | +</tr> |
| 124 | +</thead> |
| 125 | + <tbody><tr> |
| 126 | +<td>1</td> |
| 127 | +<td>"01110"</td> |
| 128 | +<td>2</td> |
| 129 | +<td>3</td> |
| 130 | +<td>"11"</td> |
| 131 | +</tr> |
| 132 | +<tr> |
| 133 | +<td>2</td> |
| 134 | +<td>"11"</td> |
| 135 | +<td>0</td> |
| 136 | +<td>2</td> |
| 137 | +<td>"10"</td> |
| 138 | +</tr> |
| 139 | +<tr> |
| 140 | +<td>3</td> |
| 141 | +<td>"10"</td> |
| 142 | +<td>1</td> |
| 143 | +<td>1</td> |
| 144 | +<td>"1"</td> |
| 145 | +</tr> |
| 146 | +</tbody> |
| 147 | + </table> |
| 148 | +<ul> |
| 149 | +<li>3번의 이진 변환을 하는 동안 3개의 0을 제거했으므로, <code>[3,3]</code>을 return 해야 합니다.</li> |
| 150 | +</ul> |
| 151 | + |
| 152 | +<p>입출력 예 #3</p> |
| 153 | + |
| 154 | +<ul> |
| 155 | +<li>"1111111"이 "1"이 될 때까지 이진 변환을 가하는 과정은 다음과 같습니다.</li> |
| 156 | +</ul> |
| 157 | +<table class="table"> |
| 158 | + <thead><tr> |
| 159 | +<th>회차</th> |
| 160 | +<th>이진 변환 이전</th> |
| 161 | +<th>제거할 0의 개수</th> |
| 162 | +<th>0 제거 후 길이</th> |
| 163 | +<th>이진 변환 결과</th> |
| 164 | +</tr> |
| 165 | +</thead> |
| 166 | + <tbody><tr> |
| 167 | +<td>1</td> |
| 168 | +<td>"1111111"</td> |
| 169 | +<td>0</td> |
| 170 | +<td>7</td> |
| 171 | +<td>"111"</td> |
| 172 | +</tr> |
| 173 | +<tr> |
| 174 | +<td>2</td> |
| 175 | +<td>"111"</td> |
| 176 | +<td>0</td> |
| 177 | +<td>3</td> |
| 178 | +<td>"11"</td> |
| 179 | +</tr> |
| 180 | +<tr> |
| 181 | +<td>3</td> |
| 182 | +<td>"11"</td> |
| 183 | +<td>0</td> |
| 184 | +<td>2</td> |
| 185 | +<td>"10"</td> |
| 186 | +</tr> |
| 187 | +<tr> |
| 188 | +<td>4</td> |
| 189 | +<td>"10"</td> |
| 190 | +<td>1</td> |
| 191 | +<td>1</td> |
| 192 | +<td>"1"</td> |
| 193 | +</tr> |
| 194 | +</tbody> |
| 195 | + </table> |
| 196 | +<ul> |
| 197 | +<li>4번의 이진 변환을 하는 동안 1개의 0을 제거했으므로, <code>[4,1]</code>을 return 해야 합니다.</li> |
| 198 | +</ul> |
| 199 | + |
| 200 | + |
| 201 | +> 출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/challenges |
0 commit comments