[Programmers] 이진 변환 반복하기 - 월간 코드 챌린지 시즌1

동민·2021년 3월 11일
// 이진 변환 반복하기 - 월간 코드 챌린지 시즌1
public class RepeatToBinary {
	public int[] solution(String s) {
		int count = 0, zero = 0;
		while (!s.equals("1")) {
			int size = s.length();
			s = s.replaceAll("0", "");
			zero += size - s.length();
			count++;
			s = Integer.toBinaryString(s.length());
		}
		return new int[] { count, zero };
	}
}
profile
BE Developer

0개의 댓글