class Solution {
public:
    void permute_(vector<int>& num,vector<vector<int>>& res,int n)
    {
        if(n==num.size()-1)
            res.push_back(num);
        else
        {
            for(int i=n;i<num.size();++i)
            {
                swap(num[i],num[n]);
                permute_(num,res,n+1);
                swap(num[i],num[n]);
            }
        }
    }
    vector<vector<int> > permute(vector<int>& num) {
        sort(num.begin(),num.end());
        vector<vector<int>> res;
        permute_(num,res,0);
        sort(res.begin(),res.end());
        return res;
    }
};