Who can tell me what went go wrong in this solution?


  • 0
    K

    this solution is quite similiar to the top discuss, but the result went wrong.

    public int change(int amount, int[] coins) {
    		int[] dp = new int[amount+1];
    		dp[0] = 1;
    		for(int i=1;i<=amount;i++){
    			for(int coin:coins){
    				if (i-coin>=0) {
    					dp[i]+=dp[i-coin];
    				}
    			}
    		}
    		return dp[amount];
        }
    

  • 0
    L

    because in your code ,for example,sequences 1,3,2,1 and 1,1,2,3 are all possible, but they are same combination with different order ,you will get depulicated ones(poor english, wish you can understand what i say)


  • 0
    L
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.