Why Runtime Error?


  • 0
    C

    class Solution {

    public:

      string getPermutation(int n, int k) {   
      vector<int> num;
      string solution;
      if(n ==0) return solution;  
      vector<int> visited(n, 0); 
      for(int i=1;i<=n;i++){
        num.push_back(i);          
      }
      return GeneratePermute(num, 0, visited, solution, k);  
    }  
    string GeneratePermute(vector<int> & num, int step, vector<int>& visited, string solution, int k)  
    {  
      if(step == num.size())  
      {  
        k--;
        if(k==0)
        return solution;  
      }  
      for(int i =0; i< num.size(); i++)  
      {  
        if(visited[i] == 0)  
        {  
          visited[i] = 1;  
          solution.push_back(num[i]+'0');  
          GeneratePermute(num, step+1, visited, solution, k);  
          solution.pop_back();  
          visited[i] =0;  
        }  
      }  
    }  
    

    };


Log in to reply
 

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