분류 전체보기
-
프로그래머스 우박수열_정적분(python)Algorithm/프로그래머스_생각정리 2022. 12. 6. 23:55
def solution(k, ranges): answer = [] height = [] width = [] while k != 1: height.append(k) if k % 2 == 0: k //= 2 else: k = k * 3 + 1 height.append(1) width.append((height[0] + height[1]) / 2) for i in range(1,len(height)-1): width.append((height[i] + height[i+1]) / 2 + width[i-1]) for x,y in ranges: y = len(height)-1 + y if x > y: answer.append(-1.0) elif x == y: answer.append(0.0) else: if x =..
-
프로그래머스 택배상자(python)Algorithm/프로그래머스_생각정리 2022. 10. 18. 17:33
from collections import deque def solution(order): data = deque([i for i in range(1,len(order)+1)]) sub_data = deque() answer = 0 o = 0 flag = 0 s_flag = 0 while True: if data: if order[o] > data[0]: sub_data.appendleft(data.popleft()) elif order[o] == data[0]: data.popleft() answer +=1 o += 1 else: flag = 1 pass else: if order[o] == sub_data[0]: answer += 1 sub_data.popleft() o += 1 if o > len(..