Skip to content

add coinChange algo#297

Closed
zhexuany wants to merge 1 commit into
TheAlgorithms:masterfrom
zhexuany:addCoinChange
Closed

add coinChange algo#297
zhexuany wants to merge 1 commit into
TheAlgorithms:masterfrom
zhexuany:addCoinChange

Conversation

@zhexuany

Copy link
Copy Markdown

No description provided.

@christianbender

Copy link
Copy Markdown

@zhexuany You must resolve your conflicts. Otherwise I can not merge your code to the project.

@christianbender christianbender left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good Work! I have some requests.

@@ -0,0 +1,18 @@
class CoinChange {
public staitc int coinChange(int[] coins, int amount) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write static instead of staitc

class CoinChange {
public staitc int coinChange(int[] coins, int amount) {
int[] dp = new int[amount+1];
Arrays.fill(dp, amount+1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add import java.util.Arrays;

dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1);
}
return dp[amount] > amount ? -1 : dp[amount];
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comments in your code

Arrays.fill(dp, amount+1);
dp[0] = 0;
for(int i = 1; i <= amount; i++) {
for(int j = 0; j < coins.length; j++)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use curly braces!

dp[0] = 0;
for(int i = 1; i <= amount; i++) {
for(int j = 0; j < coins.length; j++)
if(i >= coins[j])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use curly braces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants