간단한 문제지만 어떻게 간단하게 코드를 구현할지 중요한 문제였다.
내 풀이
def solution(lottos, win_nums):
cnt = 0
sum = 0
for lotto in lottos:
if lotto == 0:
cnt+=1
continue
else :
if lotto in win_nums:
sum+=1
answer = []
win = [sum+cnt, sum]
for num in win :
if num == 6:
answer.append(1)
elif num == 5:
answer.append(2)
elif num == 4:
answer.append(3)
elif num == 3:
answer.append(4)
elif num == 2:
answer.append(5)
elif num <= 1:
answer.append(6)
return answer
다른 사람 풀이
def solution(lottos, win_nums):
zero = lottos.count(0)
a= [x for x in lottos if x in win_nums]
max = zero+len(a)
min = len(a)
max = 7- max if max >=1 else 6
min = 7- min if min >=1 else 6
return [max,min]
count함수를 사용하여 0 개수를 count하여 풀었으며
점수는 count 개수에 따라 도출되도록 풀이한 코드였다.
'Programming > Etc' 카테고리의 다른 글
소수 찾기 효율성 (0) | 2022.02.15 |
---|---|
Programmers / 문자열 압축 (0) | 2022.02.11 |
Hackerrank / Write a function (0) | 2022.01.18 |
Hackerrank / Iterables and Iterators (0) | 2021.12.03 |
Hackerrank / ginorts (0) | 2021.12.03 |