Skip to content

Commit a19ff0f

Browse files
committed
重构
1 parent 8273935 commit a19ff0f

6 files changed

+212
-67
lines changed

C++/LeetCodet题解(C++版).pdf

7.53 KB
Binary file not shown.

C++/chapBruteforce.tex

+25
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,31 @@ \subsubsection{代码}
539539
};
540540
\end{Code}
541541

542+
\begin{Code}
543+
// LeetCode, Combinations
544+
// use prev_permutation()
545+
class Solution {
546+
public:
547+
vector<vector<int> > combine(int n, int k) {
548+
vector<int> values(n);
549+
iota(values.begin(), values.end(), 1);
550+
551+
vector<bool> select(n, false);
552+
fill_n(select.begin(), k, true);
553+
554+
vector<vector<int> > result;
555+
do{
556+
vector<int> one(k);
557+
for (int i = 0, index = 0; i < n; ++i)
558+
if (select[i])
559+
one[index++] = values[i];
560+
result.push_back(one);
561+
} while(prev_permutation(select.begin(), select.end()));
562+
return result;
563+
}
564+
};
565+
\end{Code}
566+
542567

543568
\subsubsection{相关题目}
544569
\begindot

0 commit comments

Comments
 (0)