When i execute same code at terminal it runs and give expected output but at leetcode it gives wrong output.


  • 0
    A

    class Solution {
    public:

        vector<vector<int> >v;
    

    vector<int>v1;
    void find1(int n,int k,int cur,int count,int sum)
    {
    if(count==0&&sum==n){
    v.push_back(v1);
    return ;
    }
    else if(count==0&&sum!=n)
    return ;
    for(int i=cur;i<=9;i++)
    {
    v1.push_back(i);
    find1(n,k,i+1,count-1,sum+i);
    v1.pop_back();
    }
    }
    vector<vector<int>> combinationSum3(int k, int n) {
    find1(n,k,1,k,0);
    v.clear();
    return v;
    }
    };


Log in to reply
 

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