๋ฐ์ํ
๋ฌธ์ ๋งํฌ
https://programmers.co.kr/learn/courses/30/lessons/42586/
๋์ํ์ด
- progresses์์ ํ๋์ฉ ๋ฝ์์ ์ผ์ ๋๋ง์น ์์๋ day๋ฅผ ๊ตฌํ๊ณ
- ์ด์ day๋ฅผ ์ ์ฅํด๋ ๋ณ์ pre ์ ๋น๊ตํ๋ฉด์ countํด์ค
def solution(progresses, speeds):
answer = []
count = 0
pre = 0
while progresses:
p = progresses.pop(0)
s = speeds.pop(0)
if (100-p)%s == 0:
day = (100-p)//s
else:
day = ((100-p)//s)+1
if pre == 0 :
pre = day
count += 1
elif pre >= day :
count += 1
if len(progresses) == 0:
answer.append(count)
elif pre < day:
answer.append(count)
pre = day
count = 1
if len(progresses) == 0:
answer.append(count)
return answer
๋ค๋ฅธ์ฌ๋ ํ์ด
https://programmers.co.kr/learn/courses/30/lessons/42586/solution_groups?language=python3&type=all
zip์ ํ์ฉํ ํ์ด
def solution(progresses, speeds):
Q=[]
for p, s in zip(progresses, speeds):
if len(Q)==0 or Q[-1][0]<-((p-100)//s):
Q.append([-((p-100)//s),1])
else:
Q[-1][1]+=1
return [q[1] for q in Q]
zip์ ๋ํด์ ๊ณต๋ถํ์ ๊ณต๋ถํ์ ํด๋๊ณ ๊ณต๋ถํ์ง ์์๋ค. ์ค๋ ์ง์ง zip๋ถ์๊ณ ์๋ค ใ ใ zip๊ธฐ๋ฅ์ด ๋ญ๊ธธ๋ ์ด๋ ๊ฒ๋ ํจ์จ์ ์ธ ํ์ด ๋ฐฉ๋ฒ์ด ๋์ค๋ ๊ฒ์ธ๊ฐ!
๋ฐ์ํ
'Algorithm > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] ์คํ/ํ - ๋ค๋ฆฌ๋ฅผ ์ง๋๋ ํธ๋ญ (level.2) (0) | 2021.09.15 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] ํ-๋ ๋งต๊ฒ (level.2) (0) | 2021.09.15 |
[ํ๋ก๊ทธ๋๋จธ์ค] ์ ๋ ฌ - H-Index (level.2) (0) | 2021.09.09 |
[ํ๋ก๊ทธ๋๋จธ์ค] ํด์ - ์์ฅ (level.2) (0) | 2021.09.09 |
[ํ๋ก๊ทธ๋๋จธ์ค] ํคํจ๋ ๋๋ฅด๊ธฐ (2020 ์นด์นด์ค ์ธํด์ญ ๋ฌธ์ ) (0) | 2021.09.08 |