Skip to content

Commit

Permalink
修改 0077 组合优化 c++代码 没有样式问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry-306 authored Sep 28, 2021
1 parent a3a7568 commit ed9ebe1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions problems/0077.组合优化.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

大家先回忆一下[77. 组合]给出的回溯法的代码:

```
```c++
class Solution {
private:
vector<vector<int>> result; // 存放符合条件结果的集合
Expand Down Expand Up @@ -54,7 +54,7 @@ public:
在遍历的过程中有如下代码:
```
```c++
for (int i = startIndex; i <= n; i++) {
path.push_back(i);
backtracking(n, k, i + 1);
Expand All @@ -78,7 +78,7 @@ for (int i = startIndex; i <= n; i++) {
**如果for循环选择的起始位置之后的元素个数 已经不足 我们需要的元素个数了,那么就没有必要搜索了**

注意代码中i,就是for循环里选择的起始位置。
```
```c++
for (int i = startIndex; i <= n; i++) {
```
Expand All @@ -100,13 +100,13 @@ for (int i = startIndex; i <= n; i++) {
所以优化之后的for循环是:
```
```c++
for (int i = startIndex; i <= n - (k - path.size()) + 1; i++) // i为本次搜索的起始位置
```

优化后整体代码如下:

```
```c++
class Solution {
private:
vector<vector<int>> result;
Expand Down

0 comments on commit ed9ebe1

Please sign in to comment.