[프로그래머스] PS/Java
[lv2] 이진 변환 반복하기
SH3542
2024. 12. 22. 20:12
https://school.programmers.co.kr/learn/courses/30/lessons/70129
s의 길이는 최대 15만이므로, 처음부터 toBinaryString()하면 에러 주의
class Solution {
public int[] solution(String s) {
int conv = 0;
int zero = 0;
while(!s.equals("1")) {
conv++;
int one = 0;
for(int i=0; i<s.length(); i++){
if(s.charAt(i) == '0')
zero++;
else one++;
}
s = Integer.toBinaryString(one);
}
return new int[]{conv, zero};
}
}