๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/131127
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 2๋จ๊ณ - ํ ์ธ ํ์ฌ
from collections import Counter
def solution(want, number, discount):
answer = 0
d = dict()
for i in range(len(want)):
d[want[i]] = number[i]
#num = sum(number)
# ์ด์ฐจํผ ์ต๋ 10์ด๊ธฐ ๋๋ฌธ์ ๊ตณ์ด ๊ตฌํ ํ์์์ด 10์ผ๋ก ๋ฌ๋ ๋๋ค.
for i in range(len(discount) - 9): # ์ธ๋ฑ์ค ๋ฒ์ ์กฐ์ฌ
if d == Counter(discount[i:i+10]):
answer += 1
return answer
print(solution(["banana", "apple", "rice", "pork", "pot"],[3, 2, 2, 2, 1],
["chicken", "apple", "apple", "banana", "rice", "apple", "pork", "banana", "pork", "rice", "pot", "banana", "apple", "banana"]))
Counter ๋ฅผ ์ฌ์ฉํด์ ๊ฐ๋จํ๊ฒ ํ ์ ์๋ ๋ฌธ์ .
์ธ๋ฑ์ค ์๋ฅผ ๋ ๋ฒ์๋ง ์กฐ์ฌํ๋ฉด ๋๋ค.
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
โฌ [Programmers] [Python] [Level1] ๋ฌธ์์ด ๋ด ๋ง์๋๋ก ์ ๋ ฌํ๊ธฐ (0) | 2023.04.10 |
---|---|
โฌ [Programmers] [Python] [Level2] ์ฃผ์๊ฐ๊ฒฉ (0) | 2023.04.10 |
โฌ [Programmers] [Python] [Level2] ํผ๋ก๋ (0) | 2023.04.06 |
โฌ [Programmers] [Python] [Level3] ์ต๊ณ ์ ์งํฉ (0) | 2023.04.06 |
โฌ [Programmers] [Python] Level2_์ฐ์ ๋ถ๋ถ ์์ด ํฉ์ ๊ฐ์ (0) | 2023.04.06 |