μλ° μ½λ
class Solution {
public int[] solution(String s) {
int[] answer = {};
int zero = 0;
int tran = 0;
while(!s.equals("1")){
int numOfZero = 0;
int numOfOne = 0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)=='0'){
numOfZero++;
}else{
numOfOne++;
}
}
s = Integer.toBinaryString(numOfOne);
zero+=numOfZero;
tran++;
}
return new int[]{tran,zero};
}
}
νμ΄μ¬ μ½λ
def solution(s):
answer = []
s = list(s)
numOfTrans = 0
numOfZero = 0
while s!=['1']:
value = s.count('1')
numOfZero+= s.count('0')
s=list(format(value,'b'))
numOfTrans+=1
return [numOfTrans,numOfZero]
0μ κ°―μλ₯Ό ꡬν΄μ κ³μ λμ ν©μ ꡬνκ³ 1μ κ°―μλ₯Ό ꡬν΄μ 2μ§μλ‘ λ³ννλ κ³Όμ μ μ΄μ§μ 1μ΄ λ λκΉμ§ λ°λ³΅νλ©΄ λλ€.
νμ΄μ¬μ κ²½μ° format(value,'b') λ₯Ό νμ©νκ³
μλ°μ κ²½μ° Integer.toBinaryString(value)λ₯Ό νμ©νλ©΄ λλ€.