문제
https://programmers.co.kr/learn/courses/30/lessons/42889
나의 풀이
def solution(N, stages):
answer = []
success = [0]*(N+1)
successful = []
count = len(stages)
for i in stages:
success[i-1] += 1
for i in range(len(success)-1):
if success[i] == 0:
successful.append((i+1,0))
else:
successful.append((i+1,success[i]/count))
count -= success[i]
print(successful)
successful = sorted(successful, key = lambda x: x[1], reverse=True)
print(successful)
answer = [x[0] for x in successful]
return answer
다른 사람의 풀이
def solution(N, stages):
result = {}
denominator = len(stages)
for stage in range(1, N+1):
if denominator != 0:
count = stages.count(stage)
result[stage] = count / denominator
denominator -= count
else:
result[stage] = 0
return sorted(result, key=lambda x : result[x], reverse=True)
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