Permutations
问题:全排列
class Solution { public: void dfs(vector<int> &num,vector<int> &vec2,vector<vector<int> >&vec1,int step,int vis[]) { if(step==num.size()) { vec1.push_back(vec2); return ; } for(int i=0;i<num.size();i++) { int t=num[i]; if(vis[i]==0) { vis[i]=1; vec2.push_back(t); dfs(num,vec2,vec1,step+1,vis); vec2.pop_back(); vis[i]=0; } } } vector<vector<int> > permute(vector<int> &num) { vector<vector<int> > vec1; vector<int> vec2; int vis[100]; memset(vis,0,sizeof(vis)); dfs(num,vec2,vec1,0,vis); return vec1; } };