プログラマー:宝くじの最高と最低順位(lv 1)


解答コード1

def solution(lottos, win_nums):
    answer = []
    wins, dontCare = 0, 0
    for i in lottos:
        if i == 0:
            dontCare += 1
        elif i in win_nums:
            wins += 1
    high = 7 - (wins + dontCare)
    if high > 6:
        high = 6
    low = 7 - wins
    if low > 6:
        low = 6
    
    answer.append(high)
    answer.append(low)

    return answer

解答コード2

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]