We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f14ed8a commit 68bc0f0Copy full SHA for 68bc0f0
LiiNi-coder/202510/20 PGM 이진 변환 반복하기.md
@@ -0,0 +1,31 @@
1
+```java
2
+import java.util.*;
3
+
4
+class Solution {
5
+ public int[] solution(String s) {
6
+ int[] answer = new int[]{0, 0};
7
8
+ while(!"1".equals(s)){
9
+ // 1개수 확인
10
+ int oneCount = 0;
11
+ for(int i = 0; i<s.length(); i++){
12
+ if(s.charAt(i) == '1')
13
+ oneCount++;
14
+ }
15
+ answer[1] += s.length() - oneCount;
16
+ // 이진수 s에 대입
17
+ StringBuilder sb = new StringBuilder();
18
+ while(oneCount>1){
19
+ sb.append(Integer.toString(oneCount % 2));
20
+ oneCount /= 2;
21
22
+ sb.append(Integer.toString(oneCount));
23
+ sb.reverse();
24
+ s = sb.toString();
25
+ answer[0]++;
26
27
28
+ return answer;
29
30
+}
31
+```
0 commit comments