소스 코드(초기 코드)

def solution(lottos, win_nums):
answer = []
cnt = 0
for q in win_nums:
for w in lottos:
if q == w:
cnt += 1
break
zero_cnt = lottos.count(0)
low = 7 - cnt
high = 7 - cnt - zero_cnt
if cnt == 0:
low = 6
if zero_cnt == 0:
high -= 1
answer = [high, low]
return answer

소스 코드(개선 코드)

def solution(lottos, win_nums):
answer = []
score = [6,6,5,4,3,2,1]
zero_cnt = lottos.count(0)
cnt = 0
for q in win_nums:
for w in lottos:
if q == w:
cnt += 1
break
answer = [score[zero_cnt+cnt], score[cnt]]
return answer

해결 방법

1. 당첨된 번호의 수와 0의 개수를 찾아서 계산

(최고는 당첨된 번호의 수 + 0의 개수, 최악은 당첨된 번호의 수)


느낀 점

 

 

ps. 개인적인 코드와 코드를 작성의 이유를 적은 것입니다.

 

오류적절치 않은 문법이 존재할 수 있으며, 다른 분들께는 굉장히 비효율적인 방법으로 여겨질 수 있습니다.

 

혹시 개선 사항, 오류 및 문제에 대한 수정 사항 등을 댓글로 남겨주신다면 감사한 마음으로 배우고 수정하겠습니다.