defsolution(prices): answer = [] for i inrange(len(prices)): cnt = 0 for j inrange(i+1, len(prices)): if prices[i] <= prices[j]: cnt= cnt+1 answer.append(cnt) return answer
비 효율성 문제로 통과 x
2차 답안
1 2 3 4 5 6 7 8
defsolution(prices): answer = [0] * len(prices) for i inrange(len(prices)): for j inrange(i+1, len(prices)): answer[i] += 1 if prices[i] > prices[j]: break return answer
기능개발
1차 답안
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
defsolution(progresses, speeds): answer = [] days = [] for i inrange(len(progresses)): days.append((100 - progresses[i]) / speeds[i]) for j,k inenumerate(days): if j == 0: max = k answer.append(1) continue if k <= max: answer[-1] += 1 else: max = k answer.append(1) return answer
pi_list = [(p, i) for i, p inenumerate(priorities)] waiting_q = []
while pi_list: pi = pi_list.pop(0) priority = pi[0] p_list = [priority for priority, idx in pi_list] if p_list: max_p = max(p_list) if priority >= max_p: waiting_q.append(pi) else: pi_list.append(pi) for i, item inenumerate(waiting_q): if item[1] == location: return i + 1