1 class Solution 
 2 {
 3 public:
 4     vector<vector<int>> permute(vector<int>& nums) 
 5     {
 6         vector<vector<int>> res;
 7         helper(res,0,nums);
 8         return res;
 9     }
10     
11     void helper(vector<vector<int>> &res,int beg,vector<int> &nums)
12     {
13         int sz=nums.size();
14         if(beg==sz-1)
15         {
16             res.push_back(nums);
17             return;
18         }
19         else
20         {
21             for(int i=beg;i<sz;i++)
22             {
23                 if(i!=beg)
24                 {
25                     swap(nums[i],nums[beg]);
26                     helper(res,beg+1,nums);
27                     swap(nums[i],nums[beg]);
28                 }
29                 else
30                     helper(res,beg+1,nums);        
31             } 
32         }      
33     }
34 };

交换交换交换,很骚

posted on 2018-07-10 16:15  高数考了59  阅读(108)  评论(0)    收藏  举报