-
Notifications
You must be signed in to change notification settings - Fork 5
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
22-avocado-13 #96
22-avocado-13 #96
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.
μ λ μ΄λ κ² νμ΄λ³΄μμ΅λλ€!
from math import ceil
from collections import deque
def solution(progresses, speeds):
answer = [] # κ° λ°°ν¬λ§λ€ λͺ κ°μ κΈ°λ₯μ΄ λ°°ν¬λλμ§ μ μ₯λ 리μ€νΈ
cnt = 1 # λ°°ν¬ μ μ΄κΈ°ν
period = deque([ceil((100-x)/s) for x,s in zip(progresses, speeds)]) # 걸리λ κΈ°κ° deque
first_release = period.popleft() # μμ
κΈ°κ° μ΄κΈ°ν
# deque μμκ° μ‘΄μ¬νλ λμ λ°λ³΅
while period:
# λΉκ΅ν μμ
κΈ°κ°
compared_release = period.popleft()
# λ§μ½ λ€μ κΈ°λ₯μ μμ
κΈ°κ°μ΄ νμ¬ λ°°ν¬λ κΈ°λ₯μ μμ
κΈ°κ°λ³΄λ€ 짧λ€λ©΄ λμμ λ°°ν¬(+1)
if first_release >= compared_release:
cnt += 1
# μλλΌλ©΄ μ§κΈκΉμ§ ν¨κ» λ°°ν¬ν κΈ°λ₯μ μλ₯Ό κ²°κ³Ό 리μ€νΈμ μ μ₯νκ³
# νμ¬ λ°°ν¬λ κΈ°λ₯μ μμ
κΈ°κ°κ³Ό λ°°ν¬ μλ₯Ό μ΄κΈ°ν
else:
answer.append(cnt)
first_release = compared_release
cnt = 1
answer.append(cnt)
return answer
2μ€ λ°λ³΅λ¬Έμ μ°μ§ μκ³ λ ν΄κ²°ν μ μμ΅λλ€!
22μ°¨μλ μκ³ νμ
¨μ΅λλ€ :)
|
||
def solution(progresses, speeds): | ||
answer = [] | ||
period = deque([ceil((100 - p) / s) for p, s in zip(progresses, speeds)]) |
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.
period λ°°μ΄(deque)μλ λ°°ν¬ κ°λ₯ν κΈ°κ°μ΄ νμ€ν¬λ³λ‘ μ°¨λ‘λλ‘ λ΄κΈ°λ κ±ΈκΉμ ?!
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.
λΉ! progressesμ speedsλ₯Ό zipμΌλ‘ λ¬Άμ΄μ λ°λ³΅λ¬Έμ΄ λμκ°κ³ λ°°ν¬κΉμ§ 걸리λ κΈ°κ°(kμΌ)μ ꡬν΄μ κ·Έ κΈ°κ°μ΄ period λ°°μ΄μ λ΄κΈ°λ―λ‘, μ£Όμ΄μ§ ν μ€ν¬ μμ κ·Έλλ‘ λ΄κΉλλ€!
while period: | ||
release_count = 0 | ||
first_period = period.popleft() | ||
release_count += 1 | ||
|
||
while period and period[0] <= first_period: | ||
period.popleft() | ||
release_count += 1 | ||
|
||
answer.append(release_count) | ||
|
||
return answer |
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.
μ λ 걸리λ κΈ°κ°μ λ°λ‘ ꡬνμ§ μκ³ while True 루ν νλλ₯Ό μ¬μ©ν΄μ μ½λλ₯Ό μμ±ν΄λ³΄μμ΅λλ€ !
- νμ¬ μ§ν μν©κ³Ό μλλ₯Ό κ³ λ €νμ¬, ν΄λΉ λ μ§μ κ°λ°λ μ§νλ₯ μ΄ 100μ λλμ§ νμΈν©λλ€.
- κ°λ°μ΄ μλ£ κ²½μ°μλ ν΄λΉ κΈ°λ₯μ progressesμ speedsμμ μ κ±°νκ³ , cntλ₯Ό μ¦κ°μν΅λλ€.
- λ§μ½ λͺ¨λ κΈ°λ₯μ μ§νλ₯ μ΄ 100μ λμ΄μ λ μ΄μ λ¨μμλ κΈ°λ₯μ΄ μλ€λ©΄ μ΅μ’ κ²°κ³Όλ₯Ό 리ν΄ν©λλ€.
def solution(progresses, speeds):
answer = []
day = 0
cnt = 0 #κΈ°λ₯ κ°λ°
while True:
if progresses[0] + speeds[0] * day < 100:
day += 1
if cnt >= 1:
answer.append(cnt)
cnt = 0
else:
progresses.pop(0)
speeds.pop(0)
cnt += 1
if not progresses:
answer.append(cnt)
break
return answer
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.
μ λ μ μλμ²λΌ 걸리λ κΈ°κ°μ λ°λ‘ ꡬνμ§ μκ³ λ°λ³΅λ¬Έ 루ν νλλ₯Ό μ΄μ©ν΄μ μ½λλ₯Ό μμ±νμμ΅λλ€!
λ λΆμ μλ²½ν λ¦¬λ·°λ€ λλΆμ λμ΄μ 리뷰ν κ²μ΄ μλ€μ..νν λ λΆλ°ν΄λ³΄κ² μ΅λλ·π
μ΄λ² PRλ μκ³ νμ ¨μ΄μ!β¨
π λ¬Έμ λ§ν¬
νλ‘κ·Έλλ¨Έμ€ | κΈ°λ₯ κ°λ°
λ¬Έμ μ€λͺ
νλ‘κ·Έλλ¨Έμ€ νμμλ κΈ°λ₯ κ°μ μμ μ μν μ€μ λλ€. κ° κΈ°λ₯μ μ§λκ° 100%μΌ λ μλΉμ€μ λ°μν μ μμ΅λλ€.
λ, κ° κΈ°λ₯μ κ°λ°μλλ λͺ¨λ λ€λ₯΄κΈ° λλ¬Έμ λ€μ μλ κΈ°λ₯μ΄ μμ μλ κΈ°λ₯λ³΄λ€ λ¨Όμ κ°λ°λ μ μκ³ , μ΄λ λ€μ μλ κΈ°λ₯μ μμ μλ κΈ°λ₯μ΄ λ°°ν¬λ λ ν¨κ» λ°°ν¬λ©λλ€.
λ¨Όμ λ°°ν¬λμ΄μΌ νλ μμλλ‘ μμ μ μ§λκ° μ ν μ μ λ°°μ΄ progressesμ κ° μμ μ κ°λ° μλκ° μ ν μ μ λ°°μ΄ speedsκ° μ£Όμ΄μ§ λ κ° λ°°ν¬λ§λ€ λͺ κ°μ κΈ°λ₯μ΄ λ°°ν¬λλμ§λ₯Ό return νλλ‘ solution ν¨μλ₯Ό μμ±νμΈμ.
μ ν μ¬ν
μ μΆλ ₯ μ
μ μΆλ ₯ μ μ€λͺ
μ μΆλ ₯ μ
첫 λ²μ§Έ κΈ°λ₯μ 93% μλ£λμ΄ μκ³ ν루μ 1%μ© μμ μ΄ κ°λ₯νλ―λ‘ 7μΌκ° μμ ν λ°°ν¬κ° κ°λ₯ν©λλ€. λ λ²μ§Έ κΈ°λ₯μ 30%κ° μλ£λμ΄ μκ³ ν루μ 30%μ© μμ μ΄ κ°λ₯νλ―λ‘ 3μΌκ° μμ ν λ°°ν¬κ° κ°λ₯ν©λλ€. νμ§λ§ μ΄μ 첫 λ²μ§Έ κΈ°λ₯μ΄ μμ§ μμ±λ μνκ° μλκΈ° λλ¬Έμ 첫 λ²μ§Έ κΈ°λ₯μ΄ λ°°ν¬λλ 7μΌμ§Έ λ°°ν¬λ©λλ€. μΈ λ²μ§Έ κΈ°λ₯μ 55%κ° μλ£λμ΄ μκ³ ν루μ 5%μ© μμ μ΄ κ°λ₯νλ―λ‘ 9μΌκ° μμ ν λ°°ν¬κ° κ°λ₯ν©λλ€. λ°λΌμ 7μΌμ§Έμ 2κ°μ κΈ°λ₯, 9μΌμ§Έμ 1κ°μ κΈ°λ₯μ΄ λ°°ν¬λ©λλ€.
βοΈ μμλ μκ°
40λΆ
β¨ μλ μ½λ
Note: μμ λ³ λ°°ν¬κ° κ°λ₯νκΈ°κΉμ§ μμλλ κΈ°κ°μ λ΄λ λ°°μ΄ periodλ₯Ό λ§λ€μ!
period λ°°μ΄(deque)
release_count
= νμ¬ λ°°ν¬λλ κΈ°λ₯μ μλ₯Ό λ΄μ λ³μfirst_period
= 첫λ²μ§Έ μμ κΈ°κ°μ΅μ’ μ½λ
π μλ‘κ² μκ²λ λ΄μ©