https://school.programmers.co.kr/learn/courses/30/lessons/77484
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
https://github.com/stellaluminary/Programmers
GitHub - stellaluminary/Programmers
Contribute to stellaluminary/Programmers development by creating an account on GitHub.
github.com
correct = 0, zero=0일 가능성이 있는 부분을 간과함.
def solution(lottos, win_nums):
correct, zero = 0, 0
for i in range(6):
if lottos[i] == 0:
zero += 1
continue
if lottos[i] in win_nums:
correct += 1
answer = [7 - (correct + zero), 0]
if correct in [1, 0]:
answer[1] = 6
else:
answer[1] = 7 - correct
return answer
def solution(lottos, win_nums):
grade = {6: 1, 5: 2, 4: 3, 3: 4, 2: 5, 1: 6, 0: 6}
correct, zero = 0, 0
for i in range(6):
if lottos[i] == 0:
zero += 1
elif lottos[i] in win_nums:
correct += 1
answer = [grade[correct + zero], grade[correct]]
return answer
count를 통한 0의 개수 세는 방법 + list index를 활용한 answer 계산
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]