programmers- lv.1 (로또의 최고 순위와 최저 순위)

이예송·2023년 7월 11일

PS

목록 보기
19/97

문제링크: 로또의 최고 순위와 최저 순위

✍🏻 Information

content
언어python
난이도⭐️
풀이시간7분
제출횟수1
인터넷검색유무no




🍒 My Code

def solution(lottos, win_nums):
    answer = []
    cnt = 0
    zero_cnt = lottos.count(0)
    for num in win_nums:
        if num in lottos:
            cnt+=1
    MAX = min(7-(cnt+zero_cnt),6) #7등 없으니까
    answer.append(MAX)
    MIN = min(7-cnt,6) #7등 없으니까
    answer.append(MIN)
    return answer




💡 What I learned

  • 개수 세기: .count()

  • 다른 사람의 풀이에서처럼 rank를 아래와 같이 처리할 수도 있다. 이번처럼 연속된 수가 아니라면 아래처럼 list에 넣어두는것이 더 좋은 방법일 것 같다.

def solution(lottos, win_nums):

    rank=[6,6,5,4,3,2,1]

    cnt_0 = lottos.count(0)
    ans = 0
    for x in win_nums:
        if x in lottos:
            ans += 1
    return rank[cnt_0 + ans],rank[ans]

0개의 댓글