일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 미드시청
- Daily Challenge
- 링피트
- Problem Solving
- 30분
- 만화도
- 읽기
- 프로젝트
- 괜찮음
- 운동
- leetcode
- realclass
- 리얼 클래스
- 쓰릴오브파이트
- 잡생각
- Writing
- 매일
- 스탭퍼
- 사이드
- 10분
- 영어원서읽기
- 3줄정리
- 화상영어
- 파비최
- 개발자
- FIT XR
- 월간
- 영어공부
- English
- 뭐든
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.08.11 Today's Challenge 본문
https://leetcode.com/problems/coin-change-ii/
Coin Change II - LeetCode
Can you solve this real interview question? Coin Change II - You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the number of combinations that make up that
leetcode.com
완전 탐색으로 푸는 문제!
class Solution:
def change(self, amount: int, coins: List[int]) -> int:
def solve(i, amount):
if amount == 0:
return 1
if i == len(coins):
return 0
if memo[i][amount] != -1:
return memo[i][amount]
if coins[i] > amount:
memo[i][amount] = solve(i+1, amount)
else:
memo[i][amount] = solve(i, amount-coins[i]) + solve(i+1, amount)
return memo[i][amount]
memo = [[-1] * (amount + 1) for _ in range(len(coins))]
return solve(0, amount)
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.08.13 Today's Challenge (0) | 2023.08.13 |
---|---|
2023.08.12 Today's Challenge (0) | 2023.08.12 |
2023.08.10 Today's Challenge (0) | 2023.08.10 |
2023.08.09 Today's Challenge (0) | 2023.08.09 |
2023.08.08 Today's Challenge (0) | 2023.08.08 |
Comments