|
์ฝ๋ ์์ฑํ๊ธฐ
import math
def solution(progresses, speeds) :
answer=[]
time=[]
for i in range(len(speeds)) :
time.append(math.ceil((100-progresses[i])/speeds[i]))
now=time[0]
cnt=1
for i in range(1, len(time)) :
if now>=time[i] :
cnt+=1
else:
answer.append(cnt)
now=time[i]
cnt=1
if cnt!=0 :
answer.append(cnt)
return answer
Python
๋ณต์ฌ
|
์ฝ๋ ์ค๋ช
ํ๊ธฐ
1.
๊ธฐ๋ฅ์ด ๊ฐ๋ฐ๋๋๋ฐ ํ์ํ ์์์๊ฐ์ ๊ณ์ฐํด์ time ๋ฆฌ์คํธ์ ๋ฃ๋๋ค.
2.
now์๋ ํ์ฌ ๋ฐฐํฌํ ๊ธฐ๋ฅ์ ์์์๊ฐ, cnt์๋ ๋ฐฐํฌํ ๊ธฐ๋ฅ์ ๊ฐ์๋ฅผ ์ ์ฅํ๋ค.
3.
time ๋ฆฌ์คํธ๋ฅผ ๋๋ฉด์ now๋ณด๋ค ์์์๊ฐ์ด ์๊ฑฐ๋ ๊ฐ์ผ๋ฉด cnt๋ฅผ 1 ์ฆ๊ฐ์ํค๊ณ ํฌ๋ฉด answer ๋ฐฐ์ด์ ํ์ฌ๊น์ง ๊ฐ์๋ฅผ ๋ฃ๋๋ค.
now์๋ ๋ค์ ๋ฐฐํฌํ ๊ธฐ๋ฅ์ ์์์๊ฐ์ ์ ์ฅํ๊ณ cnt๋ 1๋ก ์ด๊ธฐํ ์ํจ๋ค.
4.
๋ฆฌ์คํธ๋ฅผ ๋ค ๋๊ณ ๋์ ๋ง์ง๋ง ๋ฐฐํฌ๊ฐ๋ฅํ cnt๋ฅผ answer ๋ฆฌ์คํธ์ ๋ฃ๋๋ค.