문제링크: 이진 변환 반복하기
✍🏻 Information
| content | |
|---|---|
| 언어 | python |
| 난이도 | ⭐️+0.5 |
| 풀이시간 | 9분 |
| 제출횟수 | 1 |
| 인터넷검색유무 | no |
🍒 My Code
def solution(s):
step, zeronum = 0,0
while int(s)!=1:
step+=1
zeronum+=s.count("0")
s = len(s.replace("0",""))
binary = ""
while s>0:
binary = str(s%2)+binary
s = s//2
s = binary
return [step,zeronum]
💡 What I learned
def solution(s):
a, b = 0, 0
while s != '1':
a += 1
num = s.count('1')
b += len(s) - num
s = bin(num)[2:]
return [a, b]