728x90
programmers.co.kr/learn/courses/30/lessons/77484?language=python3
코딩테스트 연습 - 로또의 최고 순위와 최저 순위
로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호
programmers.co.kr
def solution(lottos, win_nums):
win_nums_set = set(win_nums)
lottos_set = set(lottos)
correct = win_nums_set & lottos_set
incorrect = win_nums_set - lottos_set
zero_count = 0
for i in range(6):
if not lottos[i]:
zero_count += 1
answer = [7 - len(correct) - zero_count, 7 - len(correct) if len(correct) else 6]
if answer[0] == 7:
answer[0] = 6
return answer
set을 사용해서 겹치는게 있는지 확인하였다.

'STUDY > Algorithm' 카테고리의 다른 글
| [백준] 1167 트리의 지름 python (0) | 2021.05.08 |
|---|---|
| [백준] 11726 2xn 타일링 C (0) | 2021.05.05 |
| [프로그래머스] 행렬 테두리 회전하기 python, 2021 Dev-Matching: 웹 백엔드 개발자(상반기) (0) | 2021.05.04 |
| [프로그래머스] 다단계 칫솔 판매 python, 2021 Dev-Matching: 웹 백엔드 개발자(상반기) (0) | 2021.05.04 |
| [백준] 1074 Z python (0) | 2021.05.04 |