Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 튜플
- Python
- 크레인 인형뽑기 게임
- 트라이
- jdbc
- 카카오 인턴
- CleanCode
- pycon
- 호텔 방 배정
- Spring Boot
- 티스토리 open api
- 트라이 #trie #알고리즘
- 가사 검색
- 보행자 천국
- 불량 사용자
- Open API
- 프로그래머스
- 징검다리 건너기
- trie
- bulk update
- 알고리즘
- Tistory
- 티스토리
Archives
- Today
- Total
택시짱의 개발 노트
[프로그래머스] 로또의 최고 순위와 최저 순위도움말 본문
https://programmers.co.kr/learn/courses/30/lessons/77484?language=python3
코딩테스트 연습 - 로또의 최고 순위와 최저 순위
로또 6/45(이하 '로또'로 표기)는 1부터 45까지의 숫자 중 6개를 찍어서 맞히는 대표적인 복권입니다. 아래는 로또의 순위를 정하는 방식입니다. 1 순위 당첨 내용 1 6개 번호가 모두 일치 2 5개 번호
programmers.co.kr
풀이
1. Count 로 lottos, win_nums에 포함되어 있는 값을 counting하고 counting된 값을 교집합 하여 같은 숫자의 갯수를 구한다.
2. 이때 lottos에 0이 없다면 최대 당첨과 최소 당첨 등수는 같다.
3. lottos에 0이 있다면 최대 등수는 교집합하여 나온 숫자 + 0의 갯수 일테고, 최소 등수는 교집합 하여 나온 숫자 이다.
from collections import defaultdict
from collections import Counter
def solution(lottos, win_nums):
lottos_counter = Counter(lottos)
win_nums_counter = Counter(win_nums)
coincide_num = len(lottos_counter & win_nums_counter)
if not lottos_counter.get(0):
return convert_count_rank(coincide_num), convert_count_rank(coincide_num)
# elif lottos_counter.get(0)
count_zero = lottos_counter.get(0)
return convert_count_rank(coincide_num + count_zero), convert_count_rank(coincide_num)
def convert_count_rank(coincide_num):
return 6 if coincide_num == 0 else (6 - coincide_num) % 6 + 1
반응형
'알고리즘' 카테고리의 다른 글
[백준] - 미로 탈출 (0) | 2021.08.29 |
---|---|
[프로그래머스] 위클리 챌린지4주차 (0) | 2021.08.24 |
스트리미 코테 (21) | 2021.01.12 |
tpay 코테 (0) | 2021.01.12 |
2019 카카오 인턴 코테 (0) | 2021.01.12 |
Comments