티스토리 뷰

공부

[DP] 동전문제

승가비 2020. 11. 7. 15:38
728x90

간단한 동전문제도 헷갈린다..

까먹지 않기 위해 기록!!

 

class Solution:
    def coinChange(self, coins: List[int], amount: int) -> int:
        dp = [float('inf')] * (amount + 1)
        dp[0] = 0
        
        for i in range(1, amount + 1):
            for j in coins:
                if i >= j: 
                    dp[i] = min(dp[i], dp[i - j] + 1)
        return -1 if dp[amount] == float('inf') else dp[amount]

https://leetcode.com/problems/coin-change/

 

Coin Change - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

https://mygumi.tistory.com/129

 

동전 교환 관련 문제 접근 :: 마이구미

이번 글은 "동전 교환" 에 관한 알고리즘을 다뤄볼 것이다. 백준 알고리즘 사이트에서 알고리즘 분류에서 "동전 교환"을 볼 수 있다. 2293번 동전 1, 2294번 동전 2, 11047번 동전 0 문제를 통해 다룬

mygumi.tistory.com

 

728x90

'공부' 카테고리의 다른 글

[Python] init array  (0) 2020.11.07
[Python] inf 무한대  (0) 2020.11.07
[Spark] Total size of serialized results of 16 tasks bigger than spark.driver.maxResultSize  (0) 2020.11.07
[MySQL] count connection  (0) 2020.11.07
[Pyspark] functions  (0) 2020.11.07
댓글