[구현] PRG 77484: 로또의 최고 순위와 최저 순위

KimRiun·2021년 9월 13일
0

알고리즘_문제

목록 보기
12/26

사용 언어: python 3.9.5

❓ Problem

문제 설명

https://programmers.co.kr/learn/courses/30/lessons/77484

난이도

level 1

🚩 Solution

시도 01)

1. 접근법

  1. 최저
    0 이 모두 다른 숫자라고 가정
    → 0이 아닌 숫자 중에 로또랑 같은 개수로 순위 결정

  2. 최고
    0이 모두 맞다고 가정하고 순위 결정

    → 0인 숫자 + 0이 아닌 숫자 중에 로또랑 같은 개수로 순위 결정

2. 코드

import collections
def solution(lottos, win_nums):
    lottos = sorted(lottos,reverse=True)
    win_nums = sorted(win_nums,reverse=True)

    answer = []
    cnt = 0
    cnt2 = 0
    for l in lottos:
        if l in win_nums:
           cnt += 1
        elif l == 0:
            cnt2 += 1

    answer.append(dict[cnt + cnt2])
    answer.append(dict[cnt])

    return answer

dict = collections.defaultdict(int)
dict = {6: 1, 5: 2, 4: 3, 3: 4, 2: 5, 1: 6, 0: 6}

# solution([45, 4, 35, 20, 3, 9], [20, 9, 3, 45, 4, 35])

3. 시간복잡도

O(n2)O(n^2)

4. 결과

성공

5. 소요 시간

시작: 28분

(문제 읽기 6분, 풀기 22분)

📕 피드백

1. 검색한 내용

2. 실수

3. 발전 방향 (개선/추가사항)

4. 다른 사람 풀이

profile
Java, Python

0개의 댓글