Can somebody help me understand the run time exceeded error?


  • 0
    A

    class Solution {
    public:

    vector<vector<int>> permuteUnique(vector<int>& nums) {
        //sort(nums.begin(),nums.end());
        vector<vector<int>> result;
        permute(nums,0,result);
        return result; 
    }
    
    void permute(vector<int> &nums,int begin,vector<vector<int>> &result){
        if(begin == nums.size()-1){
            result.push_back(nums);
            return;
        }else{
            for(int i=begin;i<nums.size();i++){
                if(i != begin && nums[i] == nums[begin]) continue;
                swap(nums[i],nums[begin]);
                permute(nums,begin+1,result);
                swap(nums[i],nums[begin]);
            }
        }
    }
    

    };


Log in to reply
 

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