Permutations(copy)
Given a collection of numbers, return all possible permutations.
For example,
[1,2,3] have the following permutations:
[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
class Solution {
private:
vector<vector<int>> res;
public:
void permute_help(vector<int> &nums,int begin)
{
if(begin >= nums.size()) return;
permute_help(nums, begin+1);
for(int i=0; i<begin; i++)
{
swap(nums[i], nums[begin]);
res.push_back(nums);
permute_help(nums, begin+1);
swap(nums[i], nums[begin]);
}
}
vector<vector<int>> permute(vector<int>& nums) {
res.push_back(nums);
permute_help(nums,1);
return res;
}
};
人生有些关口非狠狠的斗一下不可,不能为了混口饭吃而自甘蹉跎。