Skip to content

Commit 8228c60

Browse files
committed
이진 변환 반복하기 / 심화
1 parent c2ef4b3 commit 8228c60

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function solution(s) {
2+
let count = 0;
3+
let removed = 0;
4+
5+
while (s !== "1") {
6+
const originalLength = s.length;
7+
const newStr = s
8+
.split("")
9+
.filter((char) => char === "1")
10+
.join("");
11+
removed += originalLength - newStr.length;
12+
s = newStr.length.toString(2);
13+
count++;
14+
}
15+
16+
return [count, removed];
17+
}

0 commit comments

Comments
 (0)