from collections import deque
def solution(bridge_length, weight, truck_weights):
bridge = deque(0 for _ in range(bridge_length))
total_weight = 0
step = 0
truck_weights.reverse()
while truck_weights:
total_weight -= bridge.popleft()
if total_weight + truck_weights[-1] > weight:
bridge.append(0)
else:
truck = truck_weights.pop()
bridge.append(truck)
total_weight += truck
step += 1
step += bridge_length
return step
import math
def solution(progress, speed):
answer = []
stack = []
for progress_, speed_ in zip(progress, speed) :
remain = math.ceil((100 - progress_) / speed_)
if not stack or stack[0] >= remain :
stack.append(remain)
else :
answer.append(len(stack))
stack = [remain]
return answer + [len(stack)]
์ฌ๊ท ๋ฐฉ์
def solution(n):
if n == 0 : return ''
n, remainder = divmod(n, 3)
if remainder == 0:
remainder = 4
n -= 1
return solution(n) + str(remainder)
while ๋ฐฉ์
def solution(n):
ternary = ''
while n > 0:
n, remainder = divmod(n, 3)
if remainder == 0 :
remainder = 4
n -= 1
ternary = str(remainder) + ternary
return ternary
def solution(arr1, arr2):
h, w = len(arr1), len(arr1[0])
ans = [[arr1[i][j] + arr2[i][j] for j in range(w)] for i in range(h)]
return ans
def solution(phone_number):
return '*'*len(phone_number[:-4])+phone_number[-4:]
def solution(num):
answer = 0
while num != 1 :
if answer >= 500 :
return -1
if num % 2 == 0 :
num //= 2
else :
num = num*3 + 1
answer += 1
return answer
์ต๋๊ณต์ฝ์์ ์ต์๊ณต๋ฐฐ์
import math
def solution(a, b):
gcd_value = math.gcd(a, b) # ์ต๋๊ณต์ฝ์ ๊ณ์ฐ
lcm_value = (a * b) // gcd_value # ์ต์๊ณต๋ฐฐ์ ๊ณ์ฐ
return [gcd_value, lcm_value]