-
[프로그래머스] 로또의 최고순위와 최저순위Engineering WIKI/Programmers 2022. 4. 1. 02:25
코딩테스트 연습 - 로또의 최고 순위와 최저 순위
로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호
programmers.co.kr
풀이
def solution(lottos, win_nums): answer = [] rank = [6, 6, 5, 4, 3, 2, 1] zero_count = lottos.count(0) count = 0 for i in lottos: if i in win_nums: count += 1 answer.append(rank[zero_count + count]) answer.append(rank[count]) return answer
다른 사람 풀이
def solution(lottos, win_nums): rank = { 0: 6, 1: 6, 2: 5, 3: 4, 4: 3, 5: 2, 6: 1 } return [rank[len(set(lottos) & set(win_nums)) + lottos.count(0)], rank[len(set(lottos) & set(win_nums))]]
'Engineering WIKI > Programmers' 카테고리의 다른 글
[프로그래머스] 소수 만들기 (0) 2022.04.01 [프로그래머스] 내적 (1) 2022.04.01 [프로그래머스] 음양 더하기 (0) 2022.04.01 [프로그래머스] 없는 숫자 더하기 (0) 2022.04.01 [프로그래머스] 크레인 인형뽑기 게임 (0) 2022.04.01 [프로그래머스] 키패드 누르기 (0) 2022.04.01 [프로그래머스] 숫자 문자열과 영단어 (0) 2022.04.01 [프로그래머스] 신고 결과 받기 (0) 2022.04.01