mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-08 18:32:56 +08:00
Removing redundant if condition
for loop above if condition is starting from coin and operation is increment in loop so value of i will be always >= coin hence if condition is redundant there
This commit is contained in:
@ -29,10 +29,8 @@ public class CoinChange {
|
|||||||
|
|
||||||
for (int coin : coins) {
|
for (int coin : coins) {
|
||||||
for (int i=coin; i<amount+1; i++) {
|
for (int i=coin; i<amount+1; i++) {
|
||||||
if (i>=coin) {
|
|
||||||
combinations[i] += combinations[i-coin];
|
combinations[i] += combinations[i-coin];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// Uncomment the below line to see the state of combinations for each coin
|
// Uncomment the below line to see the state of combinations for each coin
|
||||||
// printAmount(combinations);
|
// printAmount(combinations);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user