Skip to content

Commit 2b30bd0

Browse files
authored
feat: update cpp solutions (doocs#3923)
1 parent 7070b1f commit 2b30bd0

File tree

21 files changed

+85
-64
lines changed

21 files changed

+85
-64
lines changed

lcci/04.01.Route Between Nodes/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public:
126126
for (auto& e : graph) {
127127
g[e[0]].push_back(e[1]);
128128
}
129-
function<bool(int)> dfs = [&](int i) {
129+
auto dfs = [&](this auto&& dfs, int i) -> bool {
130130
if (i == target) {
131131
return true;
132132
}

lcci/04.01.Route Between Nodes/README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public:
134134
for (auto& e : graph) {
135135
g[e[0]].push_back(e[1]);
136136
}
137-
function<bool(int)> dfs = [&](int i) {
137+
auto dfs = [&](this auto&& dfs, int i) -> bool {
138138
if (i == target) {
139139
return true;
140140
}

lcci/04.01.Route Between Nodes/Solution.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Solution {
66
for (auto& e : graph) {
77
g[e[0]].push_back(e[1]);
88
}
9-
function<bool(int)> dfs = [&](int i) {
9+
auto dfs = [&](this auto&& dfs, int i) -> bool {
1010
if (i == target) {
1111
return true;
1212
}
@@ -23,4 +23,4 @@ class Solution {
2323
};
2424
return dfs(start);
2525
}
26-
};
26+
};

lcci/04.02.Minimum Height Tree/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class Solution {
103103
class Solution {
104104
public:
105105
TreeNode* sortedArrayToBST(vector<int>& nums) {
106-
function<TreeNode*(int, int)> dfs = [&](int l, int r) -> TreeNode* {
106+
auto dfs = [&](this auto&& dfs, int l, int r) -> TreeNode* {
107107
if (l > r) {
108108
return nullptr;
109109
}

lcci/04.02.Minimum Height Tree/README_EN.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ Given sorted array: [-10,-3,0,5,9],
2424

2525

2626

27-
One possible answer is: [0,-3,9,-10,null,5],which represents the following tree:
27+
One possible answer is: [0,-3,9,-10,null,5],which represents the following tree:
2828

2929

3030

31-
0
31+
0
3232

33-
/ \
33+
/ \
3434

35-
-3 9
35+
-3 9
3636

37-
/ /
37+
/ /
3838

39-
-10 5
39+
-10 5
4040

4141
</pre>
4242

@@ -127,7 +127,7 @@ class Solution {
127127
class Solution {
128128
public:
129129
TreeNode* sortedArrayToBST(vector<int>& nums) {
130-
function<TreeNode*(int, int)> dfs = [&](int l, int r) -> TreeNode* {
130+
auto dfs = [&](this auto&& dfs, int l, int r) -> TreeNode* {
131131
if (l > r) {
132132
return nullptr;
133133
}

lcci/04.02.Minimum Height Tree/Solution.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Solution {
1111
public:
1212
TreeNode* sortedArrayToBST(vector<int>& nums) {
13-
function<TreeNode*(int, int)> dfs = [&](int l, int r) -> TreeNode* {
13+
auto dfs = [&](this auto&& dfs, int l, int r) -> TreeNode* {
1414
if (l > r) {
1515
return nullptr;
1616
}
@@ -19,4 +19,4 @@ class Solution {
1919
};
2020
return dfs(0, nums.size() - 1);
2121
}
22-
};
22+
};

solution/0100-0199/0131.Palindrome Partitioning/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ public:
149149
}
150150
vector<vector<string>> ans;
151151
vector<string> t;
152-
function<void(int)> dfs = [&](int i) {
152+
auto dfs = [&](this auto&& dfs, int i) -> void {
153153
if (i == n) {
154-
ans.push_back(t);
154+
ans.emplace_back(t);
155155
return;
156156
}
157157
for (int j = i; j < n; ++j) {
158158
if (f[i][j]) {
159-
t.push_back(s.substr(i, j - i + 1));
159+
t.emplace_back(s.substr(i, j - i + 1));
160160
dfs(j + 1);
161161
t.pop_back();
162162
}

solution/0100-0199/0131.Palindrome Partitioning/README_EN.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ public:
130130
}
131131
vector<vector<string>> ans;
132132
vector<string> t;
133-
function<void(int)> dfs = [&](int i) {
133+
auto dfs = [&](this auto&& dfs, int i) -> void {
134134
if (i == n) {
135-
ans.push_back(t);
135+
ans.emplace_back(t);
136136
return;
137137
}
138138
for (int j = i; j < n; ++j) {
139139
if (f[i][j]) {
140-
t.push_back(s.substr(i, j - i + 1));
140+
t.emplace_back(s.substr(i, j - i + 1));
141141
dfs(j + 1);
142142
t.pop_back();
143143
}

solution/0100-0199/0131.Palindrome Partitioning/Solution.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ class Solution {
1111
}
1212
vector<vector<string>> ans;
1313
vector<string> t;
14-
function<void(int)> dfs = [&](int i) {
14+
auto dfs = [&](this auto&& dfs, int i) -> void {
1515
if (i == n) {
16-
ans.push_back(t);
16+
ans.emplace_back(t);
1717
return;
1818
}
1919
for (int j = i; j < n; ++j) {
2020
if (f[i][j]) {
21-
t.push_back(s.substr(i, j - i + 1));
21+
t.emplace_back(s.substr(i, j - i + 1));
2222
dfs(j + 1);
2323
t.pop_back();
2424
}
@@ -27,4 +27,4 @@ class Solution {
2727
dfs(0);
2828
return ans;
2929
}
30-
};
30+
};

solution/1100-1199/1120.Maximum Average Subtree/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class Solution {
160160
public:
161161
double maximumAverageSubtree(TreeNode* root) {
162162
double ans = 0;
163-
function<pair<int, int>(TreeNode*)> dfs = [&](TreeNode* root) -> pair<int, int> {
163+
auto dfs = [&](this auto&& dfs, TreeNode* root) -> pair<int, int> {
164164
if (!root) {
165165
return {0, 0};
166166
}

0 commit comments

Comments
 (0)