Skip to content

Commit 9386a4d

Browse files
committed
feat: 322. Coin Change solution2
1 parent 0a619fc commit 9386a4d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

coin-change/Yiseull.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ class Solution {
33
private int answer = Integer.MAX_VALUE;
44

55
public int coinChange(int[] coins, int amount) {
6+
final int IMPOSSIBLE = amount + 1;
7+
68
int[] dp = new int[amount + 1];
7-
Arrays.fill(dp, amount + 1);
9+
Arrays.fill(dp, IMPOSSIBLE);
810
dp[0] = 0;
911

1012
for (int i = 1; i < amount + 1; i++) {
@@ -15,6 +17,6 @@ public int coinChange(int[] coins, int amount) {
1517
}
1618
}
1719

18-
return dp[amount] > amount ? -1 : dp[amount];
20+
return dp[amount] == IMPOSSIBLE ? -1 : dp[amount];
1921
}
20-
}
22+
}

0 commit comments

Comments
 (0)