Skip to content

Commit ae57ef6

Browse files
committed
revise
1 parent 50f6870 commit ae57ef6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

permutation.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Given a collection of numbers, return all possible permutations.
2+
3+
For example,
4+
[1,2,3] have the following permutations:
5+
[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
6+
7+
// 关键思想:第一个位置肯定用循环遍历一遍
8+
19
class Solution {
210
public:
311
vector<vector<int> > permute(vector<int> &num) {
@@ -14,6 +22,7 @@ class Solution {
1422
return;
1523
}
1624
for(auto i: num){
25+
// 这里查重的原因是因为无法改num的值,所以只能每次判断下加入的元素是否已经存在
1726
auto pos = find(path.begin(), path.end(), i); // return the pos or the last
1827
if(pos == path.end()){
1928
path.push_back(i);

0 commit comments

Comments
 (0)