Why is the result 0 when calculating for amount = 0?


  • 0
    A

    For this example (in Javascript):

    Coins = [1]
    Amount = 0

    If you return -1 it fails. It passes if you return 0. However, the instructions state that if you cannot make up the combination for the amount with the coins given you must return -1, and for all other cases it is looking for -1. Why is it looking for 0 in this particular case though?


  • 0
    M

    You can - by not using any coin (hence the answer 0). That's one method also.
    But I agree that the constraints could have been stated more clearly.


Log in to reply
 

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