美文网首页
permutations

permutations

作者: DaiMorph | 来源:发表于2019-06-28 00:46 被阅读0次
    class Solution {
    public:
        vector<vector<int> > permute(vector<int> &num) {
            permutation(num,0);
            return ans;
        }
        void permutation(vector<int>&num,int index){
            if(index==num.size()-1){
                ans.push_back(num);
                return;
            }
            for(int i=index;i<num.size();i++)
            {
                swap(num[index],num[i]);
                permutation(num,index+1);
                swap(num[index],num[i]);
            }
        }
    private:
        vector<vector<int>>ans;
    };
    

    相关文章

      网友评论

          本文标题:permutations

          本文链接:https://www.haomeiwen.com/subject/wmmkcctx.html