Problem Solving/Programmers
[Level 2] 이진 변환 반복하기
kmkunk
2022. 4. 7. 18:43
class Solution {
public int count = 0;
public int zero = 0;
public int[] solution(String s) {
int[] answer = new int[2];
while(!s.equals("1")) {
s = deleteZero(s);
count++;
}
answer[0] = count;
answer[1] = zero;
return answer;
}
public String deleteZero(String s) {
String temp = "";
for(int i=0; i<s.length(); i++) {
if(s.charAt(i)=='0') { zero++; }
else { temp += "1"; }
}
return Integer.toBinaryString(temp.length());
}
}