首页 > 其他 > 详细

47. Permutations II

时间:2018-07-10 19:55:16      阅读:200      评论:0      收藏:0      [点我收藏+]
 1 class Solution 
 2 {
 3 public:
 4     vector<vector<int>> permuteUnique(vector<int>& nums) 
 5     {
 6         vector<vector<int>> res;
 7         sort(nums.begin(),nums.end());
 8         helper(res,nums,0);
 9         return res;
10     }
11     
12     void helper(vector<vector<int>> &res,vector<int> nums,int beg)
13     {
14         int sz=nums.size();
15         if(beg==sz-1)
16         {
17             res.push_back(nums);
18             return ;
19         }
20         else
21         {
22             for(int i=beg;i<sz;i++)
23             {
24                 if(i!=beg&&nums[i]==nums[beg])
25                     continue;
26                 else
27                 {
28                     swap(nums[i],nums[beg]);
29                     helper(res,nums,beg+1);
30                 }
31                 
32             }
33         }
34     }
35 };

这里有个问题,为啥不用nums的引用

47. Permutations II

原文:https://www.cnblogs.com/zhuangbijingdeboke/p/9290944.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!