내 풀이 (런타임 에러 몇개 발생 10문제 중에 7문제 맞음)
from collections import Counter
def solution(N, stages):
stages_count = Counter(stages)
people = len(stages)
answer = []
fail_list = {}
for i in range(1, N+1):
fail_list[i] = stages_count[i] / people
people = people - stages_count[i]
fail_list = sorted(fail_list.items(), key = lambda item: item[1], reverse = True)
for key in fail_list:
answer.append(key[0])
return answer
내풀이 (두번째 도전)
from collections import Counter
def solution(N, stages):
stages_count = Counter(stages)
people = len(stages)
answer = []
fail_list = {}
for i in range(1, N+1):
if people != 0:
fail_list[i] = stages_count[i] / people
people = people - stages_count[i]
else:
fail_list[i] = 0
fail_list = sorted(fail_list.items(), key = lambda item: item[1], reverse = True)
for key in fail_list:
answer.append(key[0])
return answer
다른 방법
def solution(N, stages):
People = len(stages)
faillist = {}
for i in range(1, N + 1):
if People != 0:
faillist[i] = stages.count(i) / People
People -= stages.count(i)
else:
faillist[i] = 0
return sorted(faillist, key=lambda i: faillist[i], reverse=True)
'Engineering WIKI > Programmers' 카테고리의 다른 글
[프로그래머스] 최소 직사각형 (0) | 2022.04.05 |
---|---|
[프로그래머스] 두 개 뽑아서 더하기 (0) | 2022.04.05 |
[프로그래머스] 예산 (0) | 2022.04.05 |
[프로그래머스] 3진법 뒤집기 (0) | 2022.04.05 |
[프로그래머스] 폰켓몬 (0) | 2022.04.01 |
[프로그래머스] 모의고사 (0) | 2022.04.01 |
[프로그래머스] 소수 만들기 (0) | 2022.04.01 |
[프로그래머스] 내적 (0) | 2022.04.01 |