문제
나의 풀이
1. 성공
def solution(n, stages):
answer = []
stage = 1
fail = [0] * (n + 1)
for i in range(1, n + 1):
until = stages.count(i)
reach = [i for i in stages if i >= stage]
fail = until / len(reach) if len(reach) != 0 else 0
stage += 1
answer.append((i, fail))
answer = sorted(answer, key = lambda x: x[1], reverse = True)
return [i[0] for i in answer]
- 시간 복잡도
: 테스트 5 〉 통과 (4229.79ms, 18.3MB)
다른 사람 풀이
1. 프로그래머스: 효율성 좋아보임
def solution(N, stages):
answer = []
fail = []
info = [0] * (N + 2)
for stage in stages:
info[stage] += 1
for i in range(N):
be = sum(info[(i + 1):])
yet = info[i + 1]
if be == 0:
fail.append((str(i + 1), 0))
else:
fail.append((str(i + 1), yet / be))
for item in sorted(fail, key=lambda x: x[1], reverse=True):
answer.append(int(item[0]))
return answer