<오답>
def solution(lottos, win_nums):
answer = []
lottos.sort()
win_nums.sort()
cnt = 7
zero = maxrank = minrank = 0
for i in lottos:
if i in win_nums:
cnt -= 1
elif i == 0:
zero += 1
if zero == 6:
maxrank = 1
else:
maxrank = cnt-zero
if zero == 6:
minrank = 6
else:
minrank = cnt
answer.append(maxrank)
answer.append(minrank)
return answer
# 1개의 테스트 케이스 빼고 성공했다. 어디가 잘못된 걸까.
<정답>
def solution(lottos, win_nums):
answer = [0,0]
#0,1개 맞추면 6위 2개 맞추면 5등 3개 맞추면 4등 ....
rank = [6,6,5,4,3,2,1]
cnt = 0
cntz = lottos.count(0) #0의 개수를 세어 주자~
for i in lottos:
if i in win_nums:
cnt += 1
answer[0],answer[1] = rank[cnt+cntz], rank[cnt]
return answer
'문제풀이 > 프로그래머스' 카테고리의 다른 글
[프로그래머스][Lv1] - k번째 수 (Python) (0) | 2021.10.14 |
---|---|
[프로그래머스][Lv1] - 숫자 문자열과 영단어(Python) (0) | 2021.10.14 |
[프로그래머스][Lv1] - 신규 아이디 추천(Python) (0) | 2021.10.12 |
[프로그래머스] - 약수의 개수와 덧셈(Python) (0) | 2021.10.07 |
[프로그래머스] - 같은 숫자는 싫어(Python) (0) | 2021.10.07 |