๋ด ๋ต์
1def solution(plans):
2 q = []
3 answer = []
4 for plan in plans:
5 h, m = map(int, plan[1].split(':'))
6 plan[1] = h*60 + m
7 plan[2] = int(plan[2])
8 plans.sort(key = lambda x: x[1])
9
10 for plan in plans:
11 if q:
12 free_time = plan[1] - q[-1][1]
13 while q:
14 q[-1][2] -= free_time
15 free_time = -1 * q[-1][2]
16
17 print (free_time, q[-1][2])
18 if free_time < 0:
19 break
20
21 if q[-1][2] <= 0:
22 answer.append(q.pop()[0])
23
24 q.append(plan)
25 while q:
26 answer.append(q.pop()[0])
27
28 return answer
๋ค๋ฅธ ์ฌ๋ ๋ต์
1def solution(plans):
2 plans = sorted(map(lambda x: [x[0], int(x[1][:2]) * 60 + int(x[1][3:]), int(x[2])], plans), key=lambda x: -x[1])
3 q = []
4
5 while plans:
6 cur = plans.pop()
7
8 for idx, item in enumerate(q):
9 if item[0] > cur[1]:
10 q[idx][0] += cur[2]
11
12 q.append([cur[1]+cur[2], cur[0]])
13
14 q.sort()
15 return list(map(lambda x: x[1], q))
๋ฌธ์
- ๊ณผ์ ์ ๋ณด ๋ฆฌ์คํธ๊ฐ ์ฃผ์ด์ง๋ค. (๊ณผ์ : [์ด๋ฆ, ์์์๊ฐ, ๊ฑธ๋ฆฌ๋ ์๊ฐ])
- ์งํ ์ค์ธ ๊ณผ์ ์ ์๊ด์์ด ๊ณผ์ ์์ ์๊ฐ์ด ๋๋ฉด ๋ฌด์กฐ๊ฑด ์์ํ๋ค
- ์งํ ์ค์ธ ๊ณผ์ ๋ฅผ ๋๋์๋ ์ด์ ์ ๋ฉ์ถฐ๋์๋ ๊ณผ์ ๋ฅผ ์์ฐจ์ ์ผ๋ก ์งํํ๋ค
- TC
- input
[[“korean”, “11:40”, “30”], [“english”, “12:10”, “20”], [“math”, “12:30”, “40”]]