def solution(lottos, win_nums):
answer = []
match = 0
zeros = 0
for num in lottos:
if num in win_nums:
match += 1
if num == 0:
zeros += 1
winner = {0: 6, 1: 6, 2: 5, 3: 4, 4: 3, 5:2, 6:1}
best = match + zeros
answer.append(winner[best])
answer.append(winner[match])
return answer
무난하다고 생각했다. 다른 사람들 답을 보기 전까진...
def solution(lottos, win_nums):
rank = {
0: 6,
1: 6,
2: 5,
3: 4,
4: 3,
5: 2,
6: 1
}
return [rank[len(set(lottos) & set(win_nums)) + lottos.count(0)], rank[len(set(lottos) & set(win_nums))]]
이걸 두줄로 풀다니... 교집합이랑 count()를 사용해서 코드가 엄청 짧아졌다.
속도도 더 빠르지 않을까....
화이팅.