We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 87a2701 commit cd835e1Copy full SHA for cd835e1
coin-change/Yn3-3xh.java
@@ -0,0 +1,29 @@
1
+/**
2
+[문제풀이]
3
+- 배열에 주어진 수를 더해서 amount 만들기
4
+- 배열은 중복 가능
5
+- amount를 만들 수 없으면 -1
6
+- amount를 만든 동전의 최소 개수 구하기
7
+- DP
8
+time: O(N M), space: O(N)
9
+
10
+[회고]
11
+DP로 풀면 되지 않을까 라는 짐작은 가는데,
12
+아직 풀이방법이 부족하다..
13
+해결방법을 보고 겨우 이해는 했다..
14
+ */
15
+class Solution {
16
+ public int coinChange(int[] coins, int amount) {
17
+ int[] dp = new int[amount + 1];
18
+ Arrays.fill(dp, amount + 1);
19
+ dp[0] = 0;
20
21
+ for (int coin : coins) {
22
+ for (int i = coin; i <= amount; i++) {
23
+ dp[i] = Math.min(dp[i], dp[i - coin] + 1);
24
+ }
25
26
+ return dp[amount] > amount ? -1 : dp[amount];
27
28
+}
29
0 commit comments