Why my code memory limit exceed


  • 0
    A

    class Solution {
    public:
    vector<vector<int> > combine(int n, int k);
    };
    vector<vector<int> > Solution::combine(int n, int k)
    {
    vector<vector<int>> res;
    vector<int> temp;
    int count = 1;
    if( k > n )
    return res;
    while(1)
    {
    for( ; count <= n && temp.size() != k; ++count)
    {
    temp.push_back(count);
    }
    if(temp.size() == k)
    {
    res.push_back(temp);
    count = temp.back()+1;
    temp.pop_back();
    }
    if(count > n)
    {
    count = temp.back()+1;
    temp.pop_back();
    }
    if(temp.size() == 0 && count > (n-k+1))
    break;
    }
    return res;
    }


Log in to reply
 

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