标签:
class Solution { public: void swap(int &a, int &b) { int temp; temp=a; a=b; b=temp; } void permutation(vector<int>& nums, vector<vector<int>>& res, int n) { if(n==nums.size()-1) { res.push_back(nums); return; } for(int i=n;i<nums.size();i++) { swap(nums[i],nums[n]); permutation(nums,res,n+1); swap(nums[i],nums[n]); } } vector<vector<int>> permute(vector<int>& nums) { vector<vector<int>> res; if(nums.size()==0) return res; permutation(nums,res,0); return res; } };
标签:
原文地址:http://www.cnblogs.com/summerkiki/p/5545246.html