[프로그래머스] 로또의 최고 순위와 최저 순위

박신희·2022년 4월 7일
0
post-thumbnail

🤜 풀이 1

def solution(lottos, win_nums):
    score={6:1,5:2,4:3,3:4,2:5,1:6,0:6}   # 일치갯수 : 순위 _ key : value
    
    empty_num=0                           # 모르는 번호 개수
    c_num=0                               # 맞은 번호 개수

    for i in lottos:
        if i==0:
            empty_num+=1
        else:
            if i in win_nums:
                c_num+=1
                
    return [score[empty_num+c_num],score[c_num]]
  • 딕셔너리를 사용하여 푼 풀이

정말 직관적으로 짰다. 이게 바로 맞을 줄이야.
이건 오늘 푼 풀이고
아래의 풀이는 반년 전에 푼 것이다.

🤜 풀이 2

def solution(lottos, win_nums):
    answer = [6,6,5,4,3,2,1]
    is_in,zero=0,0
    
    for i in lottos:
        if i in win_nums:
            is_in+=1
            
    zero=lottos.count(0)
    
    return answer[is_in+zero],answer[is_in]
  • 리스트를 사용하여 푼 풀이

  • count함수를 사용하여 굳이 for문을 사용하지 않아도 0의 개수를 바로 구했다.

profile
log my moments 'u')/

0개의 댓글