class Solution {
public:
    vector<vector<int>> permute(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        vector<vector<int>> res;
        vector<int> path;
        trackback(res,path,nums);
        return res;
    }
    void trackback(vector<vector<int>> &res,vector<int> &path,vector<int> &nums)
    {
        if(path.size() == nums.size())
        {
            res.push_back(path);
            return ;
        }
        for(auto i:nums)
        {
            auto pos=find(path.begin(),path.end(),i);
            if(pos==path.end())
            {
                path.push_back(i);
                trackback(res,path,nums);
                path.pop_back();
            }
        }
    }
};