[201018] ํ๋ก๊ทธ๋๋จธ์ค ๊ธฐ๋ฅ๊ฐ๋ฐ
2020. 10. 20. 15:59ใ๐ฑ Algorithm
ํ์ด
- rest ๋ฆฌ์คํธ ๊ฐ์ฅ ์์ ์์(๊ธฐ์ค ์์)์ ๋ค์ ์์๋ค์ ๋น๊ต
- ์์ ๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์๊ฒ ๋์ฌ ๋ ๊น์ง ๊ณ์ ๋น๊ต (count += 1)
- ๊ธฐ์ค ์์๋ณด๋ค ํฌ๊ฑฐ๋ ๊ฐ์๊ฒ ๋์ค๋ฉด, rest ๋ฆฌ์คํธ ์ฌ๋ผ์ด์ฑ
- try ~ except ๊ตฌ๋ฌธ์ผ๋ก, IndexError ํํผ
progresses = [93,30,55]
speeds = [1,30,5]
import math
def solution(progresses, speeds):
rest = [math.ceil((100 - p)/s) for p,s in zip(progresses, speeds)]
count, i = 1, 1
answer = []
while rest:
try:
if rest[0] >= rest[i]:
count += 1
i += 1
else:
rest = rest[i:]
answer.append(count)
count, i = 1, 1
except IndexError:
answer.append(count)
break
return answer
# try ~ except ๋ด๋ถ์ if ~ else ๊ตฌ๋ฌธ ์ฌ์ฉ
# ๋ฆฌ์คํธ ์ฌ๋ผ์ด์ฑ,
'๐ฑ Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ๋ก๊ทธ๋๋จธ์ค [lv1] ์ ๊ท์์ด๋์ถ์ฒ (0) | 2021.07.22 |
---|---|
ํ๋ก๊ทธ๋๋จธ์ค [lv1] ์ซ์ ๋ฌธ์์ด๊ณผ ์๋จ์ด ํ์ด์ฌ (0) | 2021.07.21 |
ํ๋ก๊ทธ๋๋จธ์ค [lv1] ์์ฃผํ์ง ๋ชปํ ์ ์ ํ์ด์ฌ (0) | 2021.06.30 |
ํ๋ก๊ทธ๋๋จธ์ค [lv3] ๊ฐ์ฅ ๊ธด ํฐ๋ฆฐ๋๋กฌ ํ์ด์ฌ (0) | 2021.05.27 |
ํ๋ก๊ทธ๋๋จธ์ค [lv2] ๋ฐฉ๊ธ ๊ทธ ๊ณก ํ์ด์ฌ (0) | 2021.05.22 |