사용언어 : python
단순하게 if문과 else문을 이용하여 풀었다.
최고 순위는 알아볼 수 없는 번호(즉 0)
이 모두 당첨번호에 포함되는 경우이고
최저 순위는 알아볼 수 없는 번호 (즉 0)
이 모두 당첨번호에 포함되지 않는 경우이다.
count
: 알아볼 수 있는 번호 중 당첨번호와 일치하는 번호의 수이다.
zero
: 알아볼 수 없는 번호의 수이다.
answer.append(count+zero)
는 당첨가능한 최고 순위의 일치하는 번호의 수이다.
answer.append(count)
는 당첨가능한 최저 순위의 일치하는 번호의 수이다.
def solution(lottos, win_nums):
answer = []
result = []
zero = 0
count = 0
for i in lottos:
if i == 0:
zero += 1
if i in win_nums:
count += 1
answer.append(count+zero) # 최고 순위
answer.append(count) # 최저순위
for i in answer:
if i == 6:
result.append(1)
elif i == 5:
result.append(2)
elif i == 4:
result.append(3)
elif i == 3:
result.append(4)
elif i == 2:
result.append(5)
else:
result.append(6)
return result
count 함수를 사용하여 0의 개수를 구하고
rank 리스트에서 인덱스는 일치하는 번호의 개수를 의미한다.
rank[인덱스]에 로또 순위 값을 넣어 간단하게 구현하였다.
🤣똑똑해..
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]