728x90

레벨2 기능개발

import numpy as np
import math
def solution(progresses, speeds):
    answer = []
    left_time = [100]*len(progresses)
    for i in range(len(left_time)):
        left_time[i] = math.ceil((left_time[i]-progresses[i])/speeds[i])
    print(left_time)
    count = 0
    idx=0
    while idx<len(left_time):
        long = left_time[idx]
        count+=1
        idx+=1
        try:
            while long >= left_time[idx]:
                count+=1
                idx+=1
            answer.append(count)
        except:
            answer.append(count)
        count=0
    return answer

레벨2 프린터

def solution(priorities, location):
    answer = 0
    a=[]
    for i in range(len(priorities)):
        a.append([priorities[i],(len(priorities)*[0])[i]])
    a[location][1] = 1

    while a:
        if max(a)[0] != a[0][0]:
            a.append(a.pop(0))
            print(a)
        elif max(a)[0] == a[0][0]:
            b = a.pop(0)
            answer+=1
            if b[1] ==1:
                break
    return answer

레벨 2 다리를 지나는 트럭

def solution(bridge_length, weight, truck_weights):
    answer = 0
    passing=[]
    finish=[]
    start_time=[0] * len(truck_weights)
    idx=0
    idx2=0
    a=len(truck_weights)
    b=truck_weights.pop(0)
    while a!=len(finish):
        answer+=1 
        if answer - start_time[idx] == bridge_length:
            finish.append(passing.pop(0))
            idx+=1
        if len(truck_weights) != 0:
            if sum(passing)+b <=weight :
                start_time[idx2]=answer
                passing.append(b)
                idx2+=1           
                b=truck_weights.pop(0)
        elif len(truck_weights) == 0:
            if 0<sum(passing)+b <=weight :
                start_time[idx2]=answer
                passing.append(b)
                answer = start_time[idx2] + bridge_length
                break

    return answer

 

레벨 2 주식 가격

def solution(prices):
    answer = [0]*len(prices)
    for i in range(len(prices)-1):
        for j in range(i+1,len(prices)):
            if prices[i] <= prices[j]:
                answer[i]+=1
            else:
                answer[i]+=1
                break
    return answer
728x90

+ Recent posts