프로그래머스 이진 변환 반복하기 - java


프로그래머스 이진 변환 반복하기 - java

StringTokenizer를 사용하면 편리합니다. import java.util.*; class Solution { public int[] solution(String s) { int[] answer = {}; String loopResult = s; int loopCount = 0; int zeros = 0; while (!loopResult.equals("1")){ StringTokenizer st = new StringTokenizer(loopResult, "0", true); loopResult = ""; while (st.hasMoreTokens()){ String token = st.nextToken(); if (token.charAt(0) == '1') { loopResult = loopResult + token; } else { //token.charAt(0) == '0' zeros+=token.length(); } }//while int length = loopRe...



원문링크 : 프로그래머스 이진 변환 반복하기 - java