Skip to content

Commit 0c83107

Browse files
committed
Create prob7.java
1 parent b660951 commit 0c83107

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

prob7.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Solved by
3+
Hariharan, Dept of CSE
4+
*/
5+
6+
int coins( int[] coins, int amount ) {
7+
int[] table = new int[amount+1];
8+
9+
Arrays.fill( table, Integer.MAX_VALUE - 100 );
10+
table[0] = 0;
11+
12+
for ( int i = 1; i < table.length; i++ ) {
13+
for ( int j = 0; j < coins.length; j++ ) {
14+
if ( coins[j] <= i &&
15+
table[i - coins[j]] + 1 < table[i] ) {
16+
table[i] = table[i - coins[j]] + 1;
17+
}
18+
}
19+
}
20+
21+
return table[amount];
22+
}

0 commit comments

Comments
 (0)