프로그래머스 코딩테스트/Python
[프로그래머스]로또의 최고 순위와 최저 순위 Python
Coding-Su
2024. 7. 2. 16:27
728x90
문제
정답
def solution(lottos, win_nums):
answer = []
count = [0, 0]
for i in lottos:
if i in win_nums:
count[0] += 1
elif i == 0:
count[1] += 1
if count[0] + count[1] < 2:
answer.append(6)
else:
answer.append(7-(count[0] + count[1]))
if count[0] < 2:
answer.append(6)
else:
answer.append(7-count[0])
return answer
지워진 경우(0인 경우)에는 최고 순위인 경우 모두 맞는 숫자이고, 최저 순위인 경우는 모두 틀린 숫자임으로 두가지를 나눠서 배열에 저장하여 계산하였습니다.
728x90