22 Tue

์‹คํŒจ์œจ

'''
https://programmers.co.kr/learn/courses/30/lessons/42889
์‹คํŒจ์œจ
[ํ’€์ด]
0. ์Šคํ…Œ์ด์ง€์— ๋„๋‹ฌํ–ˆ์œผ๋‚˜ ์•„์ง ํด๋ฆฌ์–ดํ•˜์ง€ ๋ชปํ•œ ํ”Œ๋ ˆ์ด์–ด์˜ ์ˆ˜ / ์Šคํ…Œ์ด์ง€์— ๋„๋‹ฌํ•œ ํ”Œ๋ ˆ์ด์–ด ์ˆ˜
1. ์‹คํŒจ์œจ์„ ์˜ค๋ฆ„์ฐจ์ˆœ๊ณผ ๋‚ด๋ฆผ์ฐจ์ˆœ์ด ์„ž์—ฌ์žˆ๋Š” ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌ ํ•˜๊ธฐ
2. key = (x[0], -x[1])์„ ์‚ฌ์šฉํ•˜๋ฉด ์„ž์—ฌ์žˆ๋Š” ์ •๋ ฌ ๊ฐ€๋Šฅ.
'''
def solution(N, stages):
    failure = [stages.count(i) for i in range(1, N+2)]
    play = [sum(failure[i:]) for i in range(N)]
    rate = [(i, v[0]/v[1]) if v[1] != 0 else (i, v[0] and 1) for i, v in enumerate([a, b] for a, b in zip(failure, play))]
    return list(map(lambda x : x[0]+1, sorted(rate, key=lambda x: (x[1], -x[0]), reverse=True)))
'''
'''

Last updated

Was this helpful?