Skip to content

Commit 09bfbb3

Browse files
authored
[20251013] PGM / Lv2 / 이진 변환 반복하기 / 이강현
1 parent 862f76a commit 09bfbb3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
```java
2+
class Solution {
3+
static int convertCnt = 0;
4+
static int zeroCnt = 0;
5+
public int[] solution(String s) {
6+
while(!s.equals("1")){
7+
s = convertToBinary(s);
8+
convertCnt++;
9+
}
10+
return new int[]{convertCnt,zeroCnt};
11+
}
12+
public String convertToBinary(String s){
13+
String removedZero = s.replaceAll("0","");
14+
int num = removedZero.length();
15+
zeroCnt += s.length() - num;
16+
StringBuilder sb = new StringBuilder();
17+
18+
while(num > 0){
19+
sb.append(num%2);
20+
num /= 2;
21+
}
22+
return sb.reverse().toString();
23+
}
24+
}
25+
```

0 commit comments

Comments
 (0)