Skip to content

Commit 6081f7c

Browse files
committed
[PGS]#70129. 이진변환반복하기/lv2/20min
https://school.programmers.co.kr/learn/courses/30/lessons/70129
1 parent cdc320b commit 6081f7c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def solution(s):
2+
answer = []
3+
# 1. 문자열 속 모든 "0" 제외하기 & 제외한 0 개수 누적 합
4+
# 2. 남은 문자열 크기의 값을 이진수 변환
5+
#3. 변환된 이진수를 다시 [1]번의 입력으로 넣어 반복(문자열 길이가 1이 될때 까지)
6+
7+
a = 0
8+
rotate = 0
9+
while len(s) > 1 :
10+
cnt = 0
11+
for n in s :
12+
if n == "0" :
13+
a+=1
14+
continue
15+
cnt +=1
16+
17+
s= str(bin(cnt))[2:]
18+
rotate += 1
19+
20+
answer = [rotate , a]
21+
return answer

0 commit comments

Comments
 (0)