-
할인 행사코딩 테스트/Level 2 2022. 10. 28. 00:01반응형
https://school.programmers.co.kr/learn/courses/30/lessons/131127
def solution(want, number, discount): answer = 0 to_buy = {a: b for a, b in zip(want, number)} for index in range(len(discount) - 9): temp = to_buy.copy() for each in discount[index:index + 10]: if each in temp: temp[each] -= 1 if all(True if each <= 0 else False for each in temp.values()): answer += 1 return answer
from collections import Counter def solution(want, number, discount): answer = 0 to_buy = Counter({a: b for a, b in zip(want, number)}) for index in range(len(discount) - 9): temp = to_buy.copy() - Counter(discount[index:index + 10]) if all(True if each <= 0 else False for each in temp.values()): answer += 1 return answer
from collections import Counter solution = lambda want, number, discount: sum(1 for index in range(len(discount) - 9) if all(True if each <= 0 else False for each in (Counter({a: b for a, b in zip(want, number)}) - Counter(discount[index:index + 10])).values()))
반응형