Skip to content

Commit 6a09fcb

Browse files
committed
Added some comments to next_permutation()
1 parent 62975fc commit 6a09fcb

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

C++/chapBruteforce.tex

+7-7
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,16 @@ \subsubsection{代码}
439439
// 时间复杂度O(n!),空间复杂度O(1)
440440
class Solution {
441441
public:
442-
vector<vector<int>> permute(vector<int>& num) {
442+
vector<vector<int> > permute(vector<int> &num) {
443+
vector<vector<int> > result;
443444
sort(num.begin(), num.end());
444445

445-
vector<vector<int>> permutations;
446-
447446
do {
448-
permutations.push_back(num);
449-
} while (next_permutation(num.begin(), num.end())); // 见第2.1节
450-
451-
return permutations;
447+
result.push_back(num);
448+
// 调用的是 2.1.12 节的 next_permutation()
449+
// 而不是 std::next_permutation()
450+
} while(next_permutation(num.begin(), num.end()));
451+
return result;
452452
}
453453
};
454454
\end{Code}

C++/leetcode-cpp.pdf

35 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)