
import math
def solution(n,a,b):
cnt = 2
ans = 1
while ans < n:
if math.ceil(a/cnt) == math.ceil(b/cnt) or ans == n :
print(ans)
break
elif math.ceil(a/cnt) != math.ceil(b/cnt):
ans += 1
cnt *= 2
return ans
처음에
aa = math.ceil(a/(n//2))
bb = math.ceil(b/(n//2))
이런 식으로 변수를 따로 만들어서 계속 풀리지가 않았다 이렇게 하면 안 된다;;
위 코드 깔끔하게 정리
↓
import math
def solution(n,a,b):
cnt = 2
ans = 1
while math.ceil(a/cnt) != math.ceil(b/cnt):
ans += 1
cnt *= 2
return ans
| [파이썬/python] 프로그래머스 : 콜라 문제 (Lv.1) (0) | 2023.03.29 |
|---|---|
| [파이썬/python] 프로그래머스 : 신고 결과 받기 (Lv.1) (2022 KAKAO BLIND RECRUITMENT) (0) | 2023.03.29 |
| [파이썬/python] 프로그래머스 : 구명보트 (Lv.2) (그리디알고리즘,탐욕법) (0) | 2023.03.29 |
| [파이썬/python] 프로그래머스 : [카카오 인턴] 키패드 누르기 (Lv.1) (0) | 2023.03.29 |
| [파이썬/python] 백준 4134번 : 다음 소수(🥈4) (0) | 2023.03.28 |