Can somebody help me check my code?


  • 0
    E

    I can run it correctly. But when I submit, show me wrong answer.
    Thank u for help.

    class Solution
    {
    public:
    	void recursive(int amount, int tempAmount, int lastCoin, vector<int>& coins)
    	{
    		tempAmount += lastCoin;
    		if (tempAmount == amount)
    		{
    			++num;
    			return;
    		}
    		else if (tempAmount > amount)
    		{
    			return;
    		}
    
    		vector<int>::iterator iter;
    		for (iter = coins.begin(); iter != coins.end(); iter++)
    		{
    			if (*iter <= lastCoin)
    			{
    				recursive(amount, tempAmount, *iter, coins);
    			}
    		}
    	}
    	int change(int amount, vector<int>& coins) {
    		vector<int>::iterator iter;
    		for (iter = coins.begin(); iter != coins.end(); iter++)
    		{
    			recursive(amount, 0, *iter, coins);
    		}
    		return num;
    	}
    
    private:
    	int num = 0;
    };
    

Log in to reply
 

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