728x90

나의 풀이
def solution(s):
answer = [0, 0]
while s != '1':
s = list(s)
idx = 0
while idx < len(s):
if s[idx] == '0':
s.pop(idx)
answer[1] += 1
else:
idx += 1
s = bin(len(s))[2:]
answer[0] += 1
return answer
1의 개수를 활용한 풀이
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]
반응형
'Coding Test > Programmers' 카테고리의 다른 글
| [프로그래머스/파이썬] 3 x n 타일링 (0) | 2022.06.17 |
|---|---|
| [프로그래머스/파이썬] 점프와 순간 이동 (0) | 2022.06.17 |
| [프로그래머스/파이썬] [1차] 캐시 (0) | 2022.06.17 |
| [프로그래머스/파이썬] 스킬트리 (0) | 2022.06.17 |
| [프로그래머스/파이썬] 모음사전 (0) | 2022.06.17 |