class Solution {
public:
vector<vector<int> > permute(vector<int> &num) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<vector<int> > vvi;
permuteHelper(vvi,num,0);
return vvi;
}
void permuteHelper(vector<vector<int> >& vvi, vector<int>& num, int current) {
if (current == num.size()) {
vvi.push_back(num);
} else {
for (int i = current; i < num.size(); ++i) {
swap(num[i], num[current]);
permuteHelper(vvi, num, current+1);
swap(num[i], num[current]);
}
}
}
};
Leetcode: Permutations
最新推荐文章于 2019-01-13 06:57:25 发布