We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 62975fc commit 6a09fcbCopy full SHA for 6a09fcb
C++/chapBruteforce.tex
@@ -439,16 +439,16 @@ \subsubsection{代码}
439
// 时间复杂度O(n!),空间复杂度O(1)
440
class Solution {
441
public:
442
- vector<vector<int>> permute(vector<int>& num) {
+ vector<vector<int> > permute(vector<int> &num) {
443
+ vector<vector<int> > result;
444
sort(num.begin(), num.end());
445
- vector<vector<int>> permutations;
446
-
447
do {
448
- permutations.push_back(num);
449
- } while (next_permutation(num.begin(), num.end())); // 见第2.1节
450
451
- return permutations;
+ result.push_back(num);
+ // 调用的是 2.1.12 节的 next_permutation()
+ // 而不是 std::next_permutation()
+ } while(next_permutation(num.begin(), num.end()));
+ return result;
452
}
453
};
454
\end{Code}
C++/leetcode-cpp.pdf
35 Bytes
0 commit comments