-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
60-9kyo-hwang #213
60-9kyo-hwang #213
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์์ ์ ์๋ฐ๋ก ํ์์ ๋๋ ํด๋์ค ๊ธฐ์ค์ผ๋ก ํ์์๋๋ฐ,
ํ์ด์ฌ์ผ๋ก ํ๋ค๋ณด๋ ์ข ๋ ๊ฐ๋จํ๊ฒ ํ ์์์์ต๋๋ค!
์ ๋ ๋ฐ๋ณต๋ฌธ์ผ๋ก ์๋ก ์ฃผ์ด์ง ๊ณผ์ ๋ฅผ ๊ฐฑ์ ํ๊ณ ,
์คํ ํ๋๋ก ์ด์ ๊ณผ์ ๋ฅผ ๊ธฐ๋กํ๋ ๋ฐฉ์์ผ๋ก ํ์ด๋ดค์ต๋๋ท.
def solution(plans):
stack = []
result = []
for plan in plans:
hour, minute = map(int, plan[1].split(':'))
start_time = hour * 60 + minute
plan[1] = start_time
plan[2] = int(plan[2])
# ์์ ์๊ฐ ๊ธฐ์ค์ผ๋ก ๊ณํ ์ ๋ ฌ
plans.sort(key=lambda x: x[1])
for i in range(len(plans) - 1):
current_plan = plans[i]
next_plan = plans[i + 1]
stack.append([current_plan[0], current_plan[2]])
time_gap = next_plan[1] - current_plan[1]
# ์คํ์ ์ฒ๋ฆฌํ๋ฉด์ ๋น ์๊ฐ์ ์์ง
while stack and time_gap > 0:
top_plan, remaining_time = stack[-1]
if remaining_time <= time_gap:
stack.pop()
time_gap -= remaining_time
result.append(top_plan)
else:
stack[-1][1] -= time_gap
time_gap = 0
result.append(plans[-1][0])
while stack:
result.append(stack.pop()[0])
return result
๐ ๋ฌธ์ ๋งํฌ
๊ณผ์ ์งํํ๊ธฐ
โ๏ธ ์์๋ ์๊ฐ
1์๊ฐ ์กฐ๊ธ ๋๊ฒ...?
โจ ์๋ ์ฝ๋
1. ๋ฌธ์
๊ณผ์ ์ํ์ ๋ํ ์ ๋ณด๊ฐ [name, start, playtime] ํํ๋ก ์ฃผ์ด์ง๋ค. name์ ๊ณผ์ ์ด๋ฆ, start๋
hh:mm
ํํ์ ์์ ์๊ฐ ๋ฌธ์์ด, playtime์ ๊ณผ์ ๋ฅผ ์๋ฃํ๋ ๋ฐ ๊ฑธ๋ฆฌ๋ ์๊ฐ์ด๋ค.์๊ฐ ์์์ ๋ง๊ฒ ๊ณผ์ ๋ฅผ ์์ํ๋๋ฐ, ๋ค์๊ณผ ๊ฐ์ ๊ท์น์ด ์กด์ฌํ๋ค.
๊ณผ์ ๋ฅผ ๋๋ธ ์์๋๋ก ์ด๋ฆ์ ๋ฐฐ์ด์ ๋ด์ returnํ๋ผ.
2. ํ์ด
๋ฌธ์ ์์ ์ ์ํ ๋ก์ง์ ์ฐจ๋ถํ ์ฝ๋๋ก ๊ตฌํํ๋ฉด ๋๋ ๋ฌธ์ ๋ค.
๊ณผ์ ์ ๋ณด์ ๋ํ ํด๋์ค๋ฅผ ์๋ก ์ ์ํ๋ค.
start
,playtime
์ ๋ณด๊ฐ ๋ฌธ์์ด๋ก ์ฃผ์ด์ง๊ธฐ ๋๋ฌธ์ intํ์ผ๋ก ๋ณํํด ์ ์ฅํ๋ค. ์ด ๋ ์๊ฐ ์ ๋ณด๋ ๋ถ ๋จ์๋ก ๋ณํํ๋ค.start
์ ๋ณด๋ฅผ ๊ธฐ์ค์ผ๋ก ๋น๊ตํ ์ ์๋๋ก<
์ฐ์ฐ์๋ฅผ ์ค๋ฒ๋ก๋ฉํ๋ค(java์compareTo()
๋ฉ์๋, ํ์ด์ฌ์labmda x: x[1]
๊ณผ ๋์ผํ ์ญํ ).๊ธฐ๋ณธ์ ์ผ๋ก ์ฃผ์ด์ง๋ ๊ณผ์ ์ ๋ณด๋ค์ ์๋ก ์ ์ํ
FPlan
ํด๋์ค๋ก ๋ณํํด ์ ์ฅํ ๋ค, ์์ ์๊ฐ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ์ํจ๋ค.์ ์ฅ๋ ๊ณผ์ ์ ๋ณด๋ฅผ ์ํํ๋ค. ๋จ ๋งจ ๋ง์ง๋ง ์ ๋ณด๋ ์ํํ ํ์ ์์ด ๋ง์ง๋ง์ ๋ฌด์กฐ๊ฑด ์๋ฃ๋๊ธฐ ๋๋ฌธ์,
Plans.size() - 1
๋งํผ๋ง ์ํํ๋ค.i + 1
๋ฒ์งธ ์ ๋ณด์i
๋ฒ์งธ ์ ๋ณด์ ์์ ์๊ฐ์ ์ฐจ๋ฅผ ํตํด ์๊ฐ ์ฐจTimeDifference
๋ฅผ ๊ตฌํ๋ค.ํด๋น ์๊ฐ ์ฐจ๊ฐ ํ์ฌ
i
๋ฒ์งธ ๊ณผ์ ์์ ์๊ฐ๋ณด๋ค ์งง์ ๊ฒฝ์ฐ,i
๋ฒ์งธ ๊ณผ์ ๋TimeDifference
๋งํผ๋ง ๊ณผ์ ๋ฅผ ์ํํ๊ณPaused
์ ์ ์ฅ๋๋ค.์๋๋ผ๋ฉด
i
๋ฒ์งธ ๊ณผ์ ๋ ์๋ฃํ ์ ์๋ ๊ฒ์ด๋ฏ๋กResult
๋ฆฌ์คํธ์ ํด๋น ๊ณผ์ ์ ์ด๋ฆ์ ์ถ๊ฐํ๋ค.๊ทธ ํ ์ค๋จํ ๊ณผ์ ๋ค์ ํ์ธํ๋ค.
์ฌ๋ด) ์ด ๋ถ๋ถ์์ ์ฝ์ง์ ์ข ํด์ ํ ์ผ 4~6๊ฐ๋ฅผ ๊ณ์ ํ๋ ธ๋ค... ์ค๋จ๋ ๊ณผ์ ๋ฅผ 2๊ฐ ์ด์ ํด๊ฒฐํ ์๋ ์๊ธฐ ๋๋ฌธ์ while๋ฌธ์ผ๋ก ํ์ธํ๊ณ , ์ค๋จ๋ ๊ณผ์ ๋ฅผ ํด๊ฒฐํ๋ฉด์ ๋จ์ ์๊ฐ ์ฐจ๊ฐ ์ค์ด๋ค๊ธฐ ๋๋ฌธ์ ์ด๋ฅผ ๊ฐฑ์ ํด์ค์ผ ํ๋ค.
์ด๋ ๊ฒ Plans ๋ฆฌ์คํธ์ ์๋ ๊ณผ์ ์ ๋ณด๋ฅผ ๋ชจ๋ ํ์ธํ๋ค๋ฉด, ๋ง์ง๋ง์ผ๋ก ์ค๋จ๋ ๊ณผ์ ๋ค์ด ๋จ์์๋ ์ง ํ ๋ฒ ๋ ํ์ธํด ๋ง๋ฌด๋ฆฌํ๋ค.
์ ์ฒด ์ฝ๋
๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
์๊ฐ ๋ค๋ฃจ๋ ๋ฌธ์ ๋ ํญ์ ํธ๋ ๋ฐ ๊ณจ์น๊ฐ ์ํ๋ค...