โถ ๋ฌธ์ :
โถ ์ฝ๋ :
def solution(N, stages):
answer= []
totalUser=len(stages)
count = {}
for i in range(N):
count[i+1] = 0
stages.sort()
for stage in stages:
if stage == N+1:
continue
else:
count[stage] += 1
failure = {}
for i in range(1,N+1):
if totalUser == 0:
failure[i] = 0
else:
failure[i] = count[i]/totalUser
totalUser -= count[i]
answerHash = sorted(failure.items(), key = lambda item : item[1],reverse=True)
#Value๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ
for i in range(len(answerHash)):
answer.append(answerHash[i][0])
return answer
โถ ๋ฌธ์ ํ์ด :
1. ์ด๊ธฐ stages์ ๋ด๊ฒจ์๋ stage์ ๋ณด๋ฅผ ์ด์ฉํด ์ด ๋ช๋ฒ์ ์คํ ์ด์ง๊ฐ ๋ฑ์ฅํ๋์ง ์ธ์ฃผ์๋ค.
2. ์ดํ 1์คํ ์ด์ง๋ถํฐ ์คํจ์จ์ ๊ณ์ฐํ์๊ณ , ๋ง์ง๋ง์๋ ์ ์ฅ๋ count ํด์ํ ์ด๋ธ์์ ๊ฐ์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌ์ ์งํํ์๋ค.
'๐ฏ CodingTest > Programmers' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] ๋คํธ๊ฒ์ (0) | 2022.04.18 |
---|---|
[Programmers] ๋น๋ฐ์ง๋ (0) | 2022.04.18 |
[Programmers] ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ ๊ฒ์ (0) | 2022.04.18 |
[Programmers] ํคํจ๋ ๋๋ฅด๊ธฐ (0) | 2022.04.18 |
[Programmers] ์ซ์ ๋ฌธ์์ด๊ณผ ์๋จ์ด (0) | 2022.04.11 |