-
[프로그래머스] 실패율Engineering WIKI/Programmers 2022. 4. 2. 01:14
코딩테스트 연습 - 실패율
실패율 슈퍼 게임 개발자 오렐리는 큰 고민에 빠졌다. 그녀가 만든 프랜즈 오천성이 대성공을 거뒀지만, 요즘 신규 사용자의 수가 급감한 것이다. 원인은 신규 사용자와 기존 사용자 사이에 스
programmers.co.kr
내 풀이 (런타임 에러 몇개 발생 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 [프로그래머스] 폰켓몬 (1) 2022.04.01 [프로그래머스] 모의고사 (0) 2022.04.01 [프로그래머스] 소수 만들기 (0) 2022.04.01 [프로그래머스] 내적 (1) 2022.04.01