-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
66-9kyo-hwang #225
base: main
Are you sure you want to change the base?
66-9kyo-hwang #225
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λμ λ리λ μ¬λΌμ΄λ©μλμ° κ°μ΄ νΈλ λ¬Έμ λΌ μ¬λ°λ€μ!!!!
import collections
def can_membership(foods, want):
for food in want:
if foods[food] > 0:
return False
return True
def solution(want, number, discount):
foods = collections.defaultdict(int)
for food, count in zip(want, number):
foods[food] = count
n = len(discount)
for food in discount[:10]:
foods[food] -= 1
answer = 0
start = 0
end = 9
while True:
if can_membership(foods, want):
answer += 1
if end + 1 == n:
break
foods[discount[start]] += 1
start += 1
end += 1
foods[discount[end]] -= 1
return answer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν μΈνλ λ¬Όνκ³Ό μνλ λ¬Όνμ μλμ μΌμΌν νμ§ μκ³ , sumμΌλ‘ ν λ²μ λνμ¬ μ²λ¦¬ν κ² λ§κ³ λ λμΌν λ°©λ²μΌλ‘ νμ΄νμ΅λλ€!
μ§κΈ μκ°ν΄λ³΄λ©΄, μ κ° μ§ μ 체 μννμ¬ λνλ μ½λ보λ€
μ λ°°λ€μ²λΌ 쑰건문μΌλ‘ μλ λ λ°λ‘ κ·Έλ§λλκ² λ λμ κ² κ°λ€μπ«
def solution(want, number, discount):
left_shopping_list = {x : y for x, y in zip(want, number)}
can_sign_up = 0
for day, dc in enumerate(discount):
if dc in want:
left_shopping_list[dc] -= 1
if day < 9:
continue
elif not day == 9:
finish_dc = discount[day-10]
if finish_dc in want:
left_shopping_list[finish_dc] += 1
left_cnt = sum([max(cnt, 0) for cnt in left_shopping_list.values()])
if left_cnt == 0:
can_sign_up += 1
return can_sign_up
π λ¬Έμ λ§ν¬
ν μΈ νμ¬
βοΈ μμλ μκ°
30λΆ
β¨ μλ μ½λ
1. λ¬Έμ
10μΌ λμ νμ μκ²©μ΄ λΆμ¬λλ€. νμμ λ§€μΌ ν κ°μ§ μ νμ ν μΈλ°μ μ μλ€. μ νμ ν루μ νλλ§ κ΅¬λ§€ν μ μλ€.
μλ₯Ό λ€μ΄, 14μΌκ° [μΉν¨, μ¬κ³Ό, μ¬κ³Ό, λ°λλ, μ, μ¬κ³Ό, λΌμ§κ³ κΈ°, λ°λλ, λΌμ§κ³ κΈ°, μ, λλΉ, λ°λλ, μ¬κ³Ό, λ°λλ] μμλλ‘ μ νμ ν μΈνλ€κ³ νμ. λλ λ°λλ 3κ°, μ¬κ³Ό 2κ°, μ 2κ°, λΌμ§κ³ κΈ° 2κ°, λλΉ 1κ°λ₯Ό ν μΈν΄μ μ¬κ³ μΆλ€.
μνλ μ νμ λͺ¨λ ν μΈ λ°μ μ μλ λ μ§λ μ μ§Έ λ , λ·μ§Έ λ , λ€μ―μ§Έ λ λ‘ μ΄ 3μΌμ΄λ€.
μ΄μ κ°μ΄ νμλ±λ‘μ μνλ μ νμ λͺ¨λ ν μΈ λ°μ μ μλ νμλ±λ‘ λ μ§μ μ΄ μΌμλ₯Ό return νλ solution ν¨μλ₯Ό μμ±ν΄μΌ νλ€. κ°λ₯ν λ μ΄ μμΌλ©΄ 0μ return νλ€.
2. μ€λͺ
μ£Όμ΄μ§λ μ΄ μ ν κ°μκ° μ΅λ 100,000κ°μ΄κΈ° λλ¬Έμ, λ§€λ² 10μΌ κ° ν μΈνλ νλͺ© μλμ κ³μ°νκΈ°μ μκ°μ΄ λ무 μ€λ κ±Έλ¦°λ€.
ν μΈ κΈ°κ°μ΄ "10μΌ"λ‘ κ³ μ λμ΄ μκΈ° λλ¬Έμ, μ¬κΈ°μλ μ¬λΌμ΄λ© μλμ° κΈ°λ²μ μ¬μ©νλ κ²μ΄ μ μ νλ€.
λ¨, μ¬κΈ°μλ λ¬Έμμ΄ μμλ₯Ό μΉ΄μ΄ν ν΄μΌ νκΈ° λλ¬Έμ map μλ£κ΅¬μ‘°λ₯Ό μ¬μ©ν΄ μμ©νλ€.
string, μ¦ μ ν λ¬Έμμ΄μ keyλ‘ ν΄μ κ°κ°μ μ νλ€μ΄ λͺ κ° ν μΈ μ€μΈμ§ κΈ°λ‘νλ
NumberbyWants
λ₯Ό μ μΈνλ€.νμ μκ²©μ΄ μ΄ν μ μ§λκΈ° λλ¬Έμ, μ°μ μ΅μ΄μ 9μΌ ν μΈ μ νλ€μ κΈ°λ‘νλ€.
μ΄μ 10μΌμ§ΈλΆν° μ¬λΌμ΄λ© μλμ° κΈ°λ²μ μ μ©νλ€.
μ 체 μ½λ
π μλ‘κ² μκ²λ λ΄μ©
μ¬μ€ μ²μ νμμ λ λμ ν© λ°©μμ μ¨μ κ°μλ₯Ό ꡬνλλ°, μκ°ν΄λ³΄λ μ¬λΌμ΄λ© μκ³ λ¦¬μ¦μΌλ‘ κ°μ μΈλ κ±Έ μ€μκ°μΌλ‘ λΉ λ₯΄κ² ν μ μμ κ² κ°μ μ½λλ₯Ό μμ νλ€.