From 2071c732f7e4148062e1d00da01b044988899903 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Sat, 21 Dec 2024 08:34:02 +0800 Subject: [PATCH] feat: update cpp dfs solutions (#3874) --- .../0100-0199/0198.House Robber/README.md | 6 ++--- .../0100-0199/0198.House Robber/README_EN.md | 6 ++--- .../0100-0199/0198.House Robber/Solution.cpp | 6 ++--- .../0233.Number of Digit One/README.md | 6 ++--- .../0233.Number of Digit One/README_EN.md | 6 ++--- .../0233.Number of Digit One/Solution.cpp | 6 ++--- .../0332.Reconstruct Itinerary/README.md | 6 ++--- .../0332.Reconstruct Itinerary/README_EN.md | 6 ++--- .../0332.Reconstruct Itinerary/Solution.cpp | 8 +++---- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 8 +++---- .../README.md | 10 ++++----- .../README_EN.md | 8 +++---- .../Solution.cpp | 8 +++---- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 10 ++++----- .../0545.Boundary of Binary Tree/README.md | 20 ++++++++--------- .../0545.Boundary of Binary Tree/README_EN.md | 20 ++++++++--------- .../0545.Boundary of Binary Tree/Solution.cpp | 22 +++++++++---------- .../README.md | 12 +++++----- .../README_EN.md | 10 ++++----- .../Solution.cpp | 10 ++++----- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 6 ++--- .../0687.Longest Univalue Path/README.md | 8 +++---- .../0687.Longest Univalue Path/README_EN.md | 8 +++---- .../0687.Longest Univalue Path/Solution.cpp | 8 +++---- .../0746.Min Cost Climbing Stairs/README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 10 ++++----- .../0700-0799/0788.Rotated Digits/README.md | 10 ++++----- .../0788.Rotated Digits/README_EN.md | 8 +++---- .../0788.Rotated Digits/Solution2.cpp | 8 +++---- .../0813.Largest Sum of Averages/README.md | 12 +++++----- .../0813.Largest Sum of Averages/README_EN.md | 8 +++---- .../0813.Largest Sum of Averages/Solution.cpp | 6 ++--- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 8 +++---- solution/0800-0899/0877.Stone Game/README.md | 6 ++--- .../0800-0899/0877.Stone Game/README_EN.md | 8 +++---- .../0800-0899/0877.Stone Game/Solution.cpp | 8 +++---- .../0800-0899/0887.Super Egg Drop/README.md | 19 ++++++++-------- .../0887.Super Egg Drop/README_EN.md | 10 ++++----- .../0887.Super Egg Drop/Solution.cpp | 10 ++++----- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 10 ++++----- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 8 +++---- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 8 +++---- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 10 ++++----- .../1200-1299/1245.Tree Diameter/README.md | 8 +++---- .../1200-1299/1245.Tree Diameter/README_EN.md | 8 +++---- .../1200-1299/1245.Tree Diameter/Solution.cpp | 10 ++++----- .../1302.Deepest Leaves Sum/README.md | 8 +++---- .../1302.Deepest Leaves Sum/README_EN.md | 8 +++---- .../1302.Deepest Leaves Sum/Solution2.cpp | 8 +++---- .../1469.Find All The Lonely Nodes/README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 8 +++---- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 8 +++---- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 10 ++++----- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 8 +++---- .../README.md | 8 +++---- .../README_EN.md | 10 ++++----- .../Solution.cpp | 8 +++---- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../2376.Count Special Integers/README.md | 8 +++---- .../2376.Count Special Integers/README_EN.md | 8 +++---- .../2376.Count Special Integers/Solution.cpp | 8 +++---- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 10 ++++----- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 4 ++-- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 10 ++++----- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 10 ++++----- .../README_EN.md | 10 ++++----- .../Solution.cpp | 12 +++++----- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 8 +++---- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 8 +++---- .../README.md | 12 +++++----- .../README_EN.md | 12 +++++----- .../Solution.cpp | 6 ++--- .../Solution2.cpp | 6 ++--- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 8 +++---- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 10 ++++----- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 10 ++++----- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 8 +++---- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 8 +++---- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 12 +++++----- .../README_EN.md | 12 +++++----- .../Solution.cpp | 12 +++++----- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 8 +++---- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 8 +++---- .../README_EN.md | 8 +++---- .../Solution.cpp | 8 +++---- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- .../README.md | 6 ++--- .../README_EN.md | 6 ++--- .../Solution.cpp | 6 ++--- 187 files changed, 725 insertions(+), 726 deletions(-) diff --git a/solution/0100-0199/0198.House Robber/README.md b/solution/0100-0199/0198.House Robber/README.md index a8efc584f4e79..d4ce2f9c033a2 100644 --- a/solution/0100-0199/0198.House Robber/README.md +++ b/solution/0100-0199/0198.House Robber/README.md @@ -119,16 +119,16 @@ public: int n = nums.size(); int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } if (f[i] < 0) { - f[i] = max(nums[i] + dfs(dfs, i + 2), dfs(dfs, i + 1)); + f[i] = max(nums[i] + dfs(i + 2), dfs(i + 1)); } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; ``` diff --git a/solution/0100-0199/0198.House Robber/README_EN.md b/solution/0100-0199/0198.House Robber/README_EN.md index cefa367aedd9c..606f38a6cd853 100644 --- a/solution/0100-0199/0198.House Robber/README_EN.md +++ b/solution/0100-0199/0198.House Robber/README_EN.md @@ -118,16 +118,16 @@ public: int n = nums.size(); int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } if (f[i] < 0) { - f[i] = max(nums[i] + dfs(dfs, i + 2), dfs(dfs, i + 1)); + f[i] = max(nums[i] + dfs(i + 2), dfs(i + 1)); } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; ``` diff --git a/solution/0100-0199/0198.House Robber/Solution.cpp b/solution/0100-0199/0198.House Robber/Solution.cpp index 0bd38434ce2ad..e30f205a3913c 100644 --- a/solution/0100-0199/0198.House Robber/Solution.cpp +++ b/solution/0100-0199/0198.House Robber/Solution.cpp @@ -4,15 +4,15 @@ class Solution { int n = nums.size(); int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } if (f[i] < 0) { - f[i] = max(nums[i] + dfs(dfs, i + 2), dfs(dfs, i + 1)); + f[i] = max(nums[i] + dfs(i + 2), dfs(i + 1)); } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; diff --git a/solution/0200-0299/0233.Number of Digit One/README.md b/solution/0200-0299/0233.Number of Digit One/README.md index 5d0872a93b98c..25efc081ada8b 100644 --- a/solution/0200-0299/0233.Number of Digit One/README.md +++ b/solution/0200-0299/0233.Number of Digit One/README.md @@ -158,7 +158,7 @@ public: int m = s.size(); int f[m][m]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int cnt, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, int cnt, bool limit) -> int { if (i >= m) { return cnt; } @@ -168,14 +168,14 @@ public: int up = limit ? s[i] - '0' : 9; int ans = 0; for (int j = 0; j <= up; ++j) { - ans += dfs(dfs, i + 1, cnt + (j == 1), limit && j == up); + ans += dfs(i + 1, cnt + (j == 1), limit && j == up); } if (!limit) { f[i][cnt] = ans; } return ans; }; - return dfs(dfs, 0, 0, true); + return dfs(0, 0, true); } }; ``` diff --git a/solution/0200-0299/0233.Number of Digit One/README_EN.md b/solution/0200-0299/0233.Number of Digit One/README_EN.md index 8e234afde9d74..db018f26b680e 100644 --- a/solution/0200-0299/0233.Number of Digit One/README_EN.md +++ b/solution/0200-0299/0233.Number of Digit One/README_EN.md @@ -158,7 +158,7 @@ public: int m = s.size(); int f[m][m]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int cnt, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, int cnt, bool limit) -> int { if (i >= m) { return cnt; } @@ -168,14 +168,14 @@ public: int up = limit ? s[i] - '0' : 9; int ans = 0; for (int j = 0; j <= up; ++j) { - ans += dfs(dfs, i + 1, cnt + (j == 1), limit && j == up); + ans += dfs(i + 1, cnt + (j == 1), limit && j == up); } if (!limit) { f[i][cnt] = ans; } return ans; }; - return dfs(dfs, 0, 0, true); + return dfs(0, 0, true); } }; ``` diff --git a/solution/0200-0299/0233.Number of Digit One/Solution.cpp b/solution/0200-0299/0233.Number of Digit One/Solution.cpp index 902995f685bc8..1638f40221fec 100644 --- a/solution/0200-0299/0233.Number of Digit One/Solution.cpp +++ b/solution/0200-0299/0233.Number of Digit One/Solution.cpp @@ -5,7 +5,7 @@ class Solution { int m = s.size(); int f[m][m]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int cnt, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, int cnt, bool limit) -> int { if (i >= m) { return cnt; } @@ -15,13 +15,13 @@ class Solution { int up = limit ? s[i] - '0' : 9; int ans = 0; for (int j = 0; j <= up; ++j) { - ans += dfs(dfs, i + 1, cnt + (j == 1), limit && j == up); + ans += dfs(i + 1, cnt + (j == 1), limit && j == up); } if (!limit) { f[i][cnt] = ans; } return ans; }; - return dfs(dfs, 0, 0, true); + return dfs(0, 0, true); } }; diff --git a/solution/0300-0399/0332.Reconstruct Itinerary/README.md b/solution/0300-0399/0332.Reconstruct Itinerary/README.md index 09f9bbbeb93b4..47bb5949da498 100644 --- a/solution/0300-0399/0332.Reconstruct Itinerary/README.md +++ b/solution/0300-0399/0332.Reconstruct Itinerary/README.md @@ -131,16 +131,16 @@ public: g[ticket[0]].push_back(ticket[1]); } vector ans; - auto dfs = [&](auto&& dfs, string& f) -> void { + auto dfs = [&](this auto&& dfs, string& f) -> void { while (!g[f].empty()) { string t = g[f].back(); g[f].pop_back(); - dfs(dfs, t); + dfs(t); } ans.emplace_back(f); }; string f = "JFK"; - dfs(dfs, f); + dfs(f); reverse(ans.begin(), ans.end()); return ans; } diff --git a/solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md b/solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md index 3fcd849fbd06a..9325ce7d70470 100644 --- a/solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md +++ b/solution/0300-0399/0332.Reconstruct Itinerary/README_EN.md @@ -129,16 +129,16 @@ public: g[ticket[0]].push_back(ticket[1]); } vector ans; - auto dfs = [&](auto&& dfs, string& f) -> void { + auto dfs = [&](this auto&& dfs, string& f) -> void { while (!g[f].empty()) { string t = g[f].back(); g[f].pop_back(); - dfs(dfs, t); + dfs(t); } ans.emplace_back(f); }; string f = "JFK"; - dfs(dfs, f); + dfs(f); reverse(ans.begin(), ans.end()); return ans; } diff --git a/solution/0300-0399/0332.Reconstruct Itinerary/Solution.cpp b/solution/0300-0399/0332.Reconstruct Itinerary/Solution.cpp index daa0b3bd96ab8..3540af22fb62a 100644 --- a/solution/0300-0399/0332.Reconstruct Itinerary/Solution.cpp +++ b/solution/0300-0399/0332.Reconstruct Itinerary/Solution.cpp @@ -7,17 +7,17 @@ class Solution { g[ticket[0]].push_back(ticket[1]); } vector ans; - auto dfs = [&](auto&& dfs, string& f) -> void { + auto dfs = [&](this auto&& dfs, string& f) -> void { while (!g[f].empty()) { string t = g[f].back(); g[f].pop_back(); - dfs(dfs, t); + dfs(t); } ans.emplace_back(f); }; string f = "JFK"; - dfs(dfs, f); + dfs(f); reverse(ans.begin(), ans.end()); return ans; } -}; \ No newline at end of file +}; diff --git a/solution/0300-0399/0341.Flatten Nested List Iterator/README.md b/solution/0300-0399/0341.Flatten Nested List Iterator/README.md index 6a7fe407546a1..97e7519ddb358 100644 --- a/solution/0300-0399/0341.Flatten Nested List Iterator/README.md +++ b/solution/0300-0399/0341.Flatten Nested List Iterator/README.md @@ -212,16 +212,16 @@ public class NestedIterator implements Iterator { class NestedIterator { public: NestedIterator(vector& nestedList) { - auto dfs = [&](auto&& dfs, vector& ls) -> void { + auto dfs = [&](this auto&& dfs, vector& ls) -> void { for (auto& x : ls) { if (x.isInteger()) { nums.push_back(x.getInteger()); } else { - dfs(dfs, x.getList()); + dfs(x.getList()); } } }; - dfs(dfs, nestedList); + dfs(nestedList); } int next() { diff --git a/solution/0300-0399/0341.Flatten Nested List Iterator/README_EN.md b/solution/0300-0399/0341.Flatten Nested List Iterator/README_EN.md index 52cf400e9057b..bf114b3a44f1d 100644 --- a/solution/0300-0399/0341.Flatten Nested List Iterator/README_EN.md +++ b/solution/0300-0399/0341.Flatten Nested List Iterator/README_EN.md @@ -210,16 +210,16 @@ public class NestedIterator implements Iterator { class NestedIterator { public: NestedIterator(vector& nestedList) { - auto dfs = [&](auto&& dfs, vector& ls) -> void { + auto dfs = [&](this auto&& dfs, vector& ls) -> void { for (auto& x : ls) { if (x.isInteger()) { nums.push_back(x.getInteger()); } else { - dfs(dfs, x.getList()); + dfs(x.getList()); } } }; - dfs(dfs, nestedList); + dfs(nestedList); } int next() { diff --git a/solution/0300-0399/0341.Flatten Nested List Iterator/Solution.cpp b/solution/0300-0399/0341.Flatten Nested List Iterator/Solution.cpp index dde245ec010a3..3804180c3df41 100644 --- a/solution/0300-0399/0341.Flatten Nested List Iterator/Solution.cpp +++ b/solution/0300-0399/0341.Flatten Nested List Iterator/Solution.cpp @@ -19,16 +19,16 @@ class NestedIterator { public: NestedIterator(vector& nestedList) { - auto dfs = [&](auto&& dfs, vector& ls) -> void { + auto dfs = [&](this auto&& dfs, vector& ls) -> void { for (auto& x : ls) { if (x.isInteger()) { nums.push_back(x.getInteger()); } else { - dfs(dfs, x.getList()); + dfs(x.getList()); } } }; - dfs(dfs, nestedList); + dfs(nestedList); } int next() { @@ -48,4 +48,4 @@ class NestedIterator { * Your NestedIterator object will be instantiated and called as such: * NestedIterator i(nestedList); * while (i.hasNext()) cout << i.next(); - */ \ No newline at end of file + */ diff --git a/solution/0300-0399/0357.Count Numbers with Unique Digits/README.md b/solution/0300-0399/0357.Count Numbers with Unique Digits/README.md index 186ce882a509a..ddfd75ff2b249 100644 --- a/solution/0300-0399/0357.Count Numbers with Unique Digits/README.md +++ b/solution/0300-0399/0357.Count Numbers with Unique Digits/README.md @@ -29,7 +29,7 @@ tags:
 输入:n = 2
 输出:91
-解释:答案应为除去 11、22、33、44、55、66、77、88、99 外,在 0 ≤ x < 100 范围内的所有数字。 
+解释:答案应为除去 11、22、33、44、55、66、77、88、99 外,在 0 ≤ x < 100 范围内的所有数字。
 

示例 2:

@@ -171,7 +171,7 @@ public: int countNumbersWithUniqueDigits(int n) { int f[n + 1][1 << 10]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int mask, bool lead) -> int { + auto dfs = [&](this auto&& dfs, int i, int mask, bool lead) -> int { if (i < 0) { return 1; } @@ -184,9 +184,9 @@ public: continue; } if (lead && j == 0) { - ans += dfs(dfs, i - 1, mask, true); + ans += dfs(i - 1, mask, true); } else { - ans += dfs(dfs, i - 1, mask | 1 << i, false); + ans += dfs(i - 1, mask | 1 << i, false); } } if (!lead) { @@ -194,7 +194,7 @@ public: } return ans; }; - return dfs(dfs, n - 1, 0, true); + return dfs(n - 1, 0, true); } }; ``` diff --git a/solution/0300-0399/0357.Count Numbers with Unique Digits/README_EN.md b/solution/0300-0399/0357.Count Numbers with Unique Digits/README_EN.md index 05df4166af3c1..639d65ff9293a 100644 --- a/solution/0300-0399/0357.Count Numbers with Unique Digits/README_EN.md +++ b/solution/0300-0399/0357.Count Numbers with Unique Digits/README_EN.md @@ -163,7 +163,7 @@ public: int countNumbersWithUniqueDigits(int n) { int f[n + 1][1 << 10]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int mask, bool lead) -> int { + auto dfs = [&](this auto&& dfs, int i, int mask, bool lead) -> int { if (i < 0) { return 1; } @@ -176,9 +176,9 @@ public: continue; } if (lead && j == 0) { - ans += dfs(dfs, i - 1, mask, true); + ans += dfs(i - 1, mask, true); } else { - ans += dfs(dfs, i - 1, mask | 1 << i, false); + ans += dfs(i - 1, mask | 1 << i, false); } } if (!lead) { @@ -186,7 +186,7 @@ public: } return ans; }; - return dfs(dfs, n - 1, 0, true); + return dfs(n - 1, 0, true); } }; ``` diff --git a/solution/0300-0399/0357.Count Numbers with Unique Digits/Solution.cpp b/solution/0300-0399/0357.Count Numbers with Unique Digits/Solution.cpp index 461100326c921..1329ce85bf331 100644 --- a/solution/0300-0399/0357.Count Numbers with Unique Digits/Solution.cpp +++ b/solution/0300-0399/0357.Count Numbers with Unique Digits/Solution.cpp @@ -3,7 +3,7 @@ class Solution { int countNumbersWithUniqueDigits(int n) { int f[n + 1][1 << 10]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int mask, bool lead) -> int { + auto dfs = [&](this auto&& dfs, int i, int mask, bool lead) -> int { if (i < 0) { return 1; } @@ -16,9 +16,9 @@ class Solution { continue; } if (lead && j == 0) { - ans += dfs(dfs, i - 1, mask, true); + ans += dfs(i - 1, mask, true); } else { - ans += dfs(dfs, i - 1, mask | 1 << i, false); + ans += dfs(i - 1, mask | 1 << i, false); } } if (!lead) { @@ -26,6 +26,6 @@ class Solution { } return ans; }; - return dfs(dfs, n - 1, 0, true); + return dfs(n - 1, 0, true); } }; diff --git a/solution/0500-0599/0530.Minimum Absolute Difference in BST/README.md b/solution/0500-0599/0530.Minimum Absolute Difference in BST/README.md index 1c4d16502b73e..ae489a790295e 100644 --- a/solution/0500-0599/0530.Minimum Absolute Difference in BST/README.md +++ b/solution/0500-0599/0530.Minimum Absolute Difference in BST/README.md @@ -154,16 +154,16 @@ public: int getMinimumDifference(TreeNode* root) { const int inf = 1 << 30; int ans = inf, pre = -inf; - auto dfs = [&](auto&& dfs, TreeNode* root) -> void { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> void { if (!root) { return; } - dfs(dfs, root->left); + dfs(root->left); ans = min(ans, root->val - pre); pre = root->val; - dfs(dfs, root->right); + dfs(root->right); }; - dfs(dfs, root); + dfs(root); return ans; } }; diff --git a/solution/0500-0599/0530.Minimum Absolute Difference in BST/README_EN.md b/solution/0500-0599/0530.Minimum Absolute Difference in BST/README_EN.md index ee82a161f1f67..254055cde1b8f 100644 --- a/solution/0500-0599/0530.Minimum Absolute Difference in BST/README_EN.md +++ b/solution/0500-0599/0530.Minimum Absolute Difference in BST/README_EN.md @@ -149,16 +149,16 @@ public: int getMinimumDifference(TreeNode* root) { const int inf = 1 << 30; int ans = inf, pre = -inf; - auto dfs = [&](auto&& dfs, TreeNode* root) -> void { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> void { if (!root) { return; } - dfs(dfs, root->left); + dfs(root->left); ans = min(ans, root->val - pre); pre = root->val; - dfs(dfs, root->right); + dfs(root->right); }; - dfs(dfs, root); + dfs(root); return ans; } }; diff --git a/solution/0500-0599/0530.Minimum Absolute Difference in BST/Solution.cpp b/solution/0500-0599/0530.Minimum Absolute Difference in BST/Solution.cpp index aefc98065b5ba..64e7154e228ff 100644 --- a/solution/0500-0599/0530.Minimum Absolute Difference in BST/Solution.cpp +++ b/solution/0500-0599/0530.Minimum Absolute Difference in BST/Solution.cpp @@ -14,16 +14,16 @@ class Solution { int getMinimumDifference(TreeNode* root) { const int inf = 1 << 30; int ans = inf, pre = -inf; - auto dfs = [&](auto&& dfs, TreeNode* root) -> void { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> void { if (!root) { return; } - dfs(dfs, root->left); + dfs(root->left); ans = min(ans, root->val - pre); pre = root->val; - dfs(dfs, root->right); + dfs(root->right); }; - dfs(dfs, root); + dfs(root); return ans; } -}; \ No newline at end of file +}; diff --git a/solution/0500-0599/0545.Boundary of Binary Tree/README.md b/solution/0500-0599/0545.Boundary of Binary Tree/README.md index 57937625d0e11..73025fd7b63c8 100644 --- a/solution/0500-0599/0545.Boundary of Binary Tree/README.md +++ b/solution/0500-0599/0545.Boundary of Binary Tree/README.md @@ -216,7 +216,7 @@ class Solution { class Solution { public: vector boundaryOfBinaryTree(TreeNode* root) { - auto dfs = [&](auto&& dfs, vector& nums, TreeNode* root, int i) -> void { + auto dfs = [&](this auto&& dfs, vector& nums, TreeNode* root, int i) -> void { if (!root) { return; } @@ -224,25 +224,25 @@ public: if (root->left != root->right) { nums.push_back(root->val); if (root->left) { - dfs(dfs, nums, root->left, i); + dfs(nums, root->left, i); } else { - dfs(dfs, nums, root->right, i); + dfs(nums, root->right, i); } } } else if (i == 1) { if (root->left == root->right) { nums.push_back(root->val); } else { - dfs(dfs, nums, root->left, i); - dfs(dfs, nums, root->right, i); + dfs(nums, root->left, i); + dfs(nums, root->right, i); } } else { if (root->left != root->right) { nums.push_back(root->val); if (root->right) { - dfs(dfs, nums, root->right, i); + dfs(nums, root->right, i); } else { - dfs(dfs, nums, root->left, i); + dfs(nums, root->left, i); } } } @@ -252,9 +252,9 @@ public: return ans; } vector left, right, leaves; - dfs(dfs, left, root->left, 0); - dfs(dfs, leaves, root, 1); - dfs(dfs, right, root->right, 2); + dfs(left, root->left, 0); + dfs(leaves, root, 1); + dfs(right, root->right, 2); ans.insert(ans.end(), left.begin(), left.end()); ans.insert(ans.end(), leaves.begin(), leaves.end()); ans.insert(ans.end(), right.rbegin(), right.rend()); diff --git a/solution/0500-0599/0545.Boundary of Binary Tree/README_EN.md b/solution/0500-0599/0545.Boundary of Binary Tree/README_EN.md index 1dc56084d68d6..4f10da50e84bf 100644 --- a/solution/0500-0599/0545.Boundary of Binary Tree/README_EN.md +++ b/solution/0500-0599/0545.Boundary of Binary Tree/README_EN.md @@ -219,7 +219,7 @@ class Solution { class Solution { public: vector boundaryOfBinaryTree(TreeNode* root) { - auto dfs = [&](auto&& dfs, vector& nums, TreeNode* root, int i) -> void { + auto dfs = [&](this auto&& dfs, vector& nums, TreeNode* root, int i) -> void { if (!root) { return; } @@ -227,25 +227,25 @@ public: if (root->left != root->right) { nums.push_back(root->val); if (root->left) { - dfs(dfs, nums, root->left, i); + dfs(nums, root->left, i); } else { - dfs(dfs, nums, root->right, i); + dfs(nums, root->right, i); } } } else if (i == 1) { if (root->left == root->right) { nums.push_back(root->val); } else { - dfs(dfs, nums, root->left, i); - dfs(dfs, nums, root->right, i); + dfs(nums, root->left, i); + dfs(nums, root->right, i); } } else { if (root->left != root->right) { nums.push_back(root->val); if (root->right) { - dfs(dfs, nums, root->right, i); + dfs(nums, root->right, i); } else { - dfs(dfs, nums, root->left, i); + dfs(nums, root->left, i); } } } @@ -255,9 +255,9 @@ public: return ans; } vector left, right, leaves; - dfs(dfs, left, root->left, 0); - dfs(dfs, leaves, root, 1); - dfs(dfs, right, root->right, 2); + dfs(left, root->left, 0); + dfs(leaves, root, 1); + dfs(right, root->right, 2); ans.insert(ans.end(), left.begin(), left.end()); ans.insert(ans.end(), leaves.begin(), leaves.end()); ans.insert(ans.end(), right.rbegin(), right.rend()); diff --git a/solution/0500-0599/0545.Boundary of Binary Tree/Solution.cpp b/solution/0500-0599/0545.Boundary of Binary Tree/Solution.cpp index 3248893353a42..4cfde8248b14d 100644 --- a/solution/0500-0599/0545.Boundary of Binary Tree/Solution.cpp +++ b/solution/0500-0599/0545.Boundary of Binary Tree/Solution.cpp @@ -12,7 +12,7 @@ class Solution { public: vector boundaryOfBinaryTree(TreeNode* root) { - auto dfs = [&](auto&& dfs, vector& nums, TreeNode* root, int i) -> void { + auto dfs = [&](this auto&& dfs, vector& nums, TreeNode* root, int i) -> void { if (!root) { return; } @@ -20,25 +20,25 @@ class Solution { if (root->left != root->right) { nums.push_back(root->val); if (root->left) { - dfs(dfs, nums, root->left, i); + dfs(nums, root->left, i); } else { - dfs(dfs, nums, root->right, i); + dfs(nums, root->right, i); } } } else if (i == 1) { if (root->left == root->right) { nums.push_back(root->val); } else { - dfs(dfs, nums, root->left, i); - dfs(dfs, nums, root->right, i); + dfs(nums, root->left, i); + dfs(nums, root->right, i); } } else { if (root->left != root->right) { nums.push_back(root->val); if (root->right) { - dfs(dfs, nums, root->right, i); + dfs(nums, root->right, i); } else { - dfs(dfs, nums, root->left, i); + dfs(nums, root->left, i); } } } @@ -48,12 +48,12 @@ class Solution { return ans; } vector left, right, leaves; - dfs(dfs, left, root->left, 0); - dfs(dfs, leaves, root, 1); - dfs(dfs, right, root->right, 2); + dfs(left, root->left, 0); + dfs(leaves, root, 1); + dfs(right, root->right, 2); ans.insert(ans.end(), left.begin(), left.end()); ans.insert(ans.end(), leaves.begin(), leaves.end()); ans.insert(ans.end(), right.rbegin(), right.rend()); return ans; } -}; \ No newline at end of file +}; diff --git a/solution/0500-0599/0552.Student Attendance Record II/README.md b/solution/0500-0599/0552.Student Attendance Record II/README.md index d62167724f4aa..6813b633353c7 100644 --- a/solution/0500-0599/0552.Student Attendance Record II/README.md +++ b/solution/0500-0599/0552.Student Attendance Record II/README.md @@ -42,7 +42,7 @@ tags: 输出:8 解释: 有 8 种长度为 2 的记录将被视为可奖励: -"PP" , "AP", "PA", "LP", "PL", "AL", "LA", "LL" +"PP" , "AP", "PA", "LP", "PL", "AL", "LA", "LL" 只有"AA"不会被视为可奖励,因为缺勤次数为 2 次(需要少于 2 次)。 @@ -158,23 +158,23 @@ public: int f[n][2][3]; memset(f, -1, sizeof(f)); const int mod = 1e9 + 7; - auto dfs = [&](auto&& dfs, int i, int j, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> int { if (i >= n) { return 1; } if (f[i][j][k] != -1) { return f[i][j][k]; } - int ans = dfs(dfs, i + 1, j, 0); + int ans = dfs(i + 1, j, 0); if (j == 0) { - ans = (ans + dfs(dfs, i + 1, j + 1, 0)) % mod; + ans = (ans + dfs(i + 1, j + 1, 0)) % mod; } if (k < 2) { - ans = (ans + dfs(dfs, i + 1, j, k + 1)) % mod; + ans = (ans + dfs(i + 1, j, k + 1)) % mod; } return f[i][j][k] = ans; }; - return dfs(dfs, 0, 0, 0); + return dfs(0, 0, 0); } }; ``` diff --git a/solution/0500-0599/0552.Student Attendance Record II/README_EN.md b/solution/0500-0599/0552.Student Attendance Record II/README_EN.md index d7e0d74bd576a..96f57054d477a 100644 --- a/solution/0500-0599/0552.Student Attendance Record II/README_EN.md +++ b/solution/0500-0599/0552.Student Attendance Record II/README_EN.md @@ -140,23 +140,23 @@ public: int f[n][2][3]; memset(f, -1, sizeof(f)); const int mod = 1e9 + 7; - auto dfs = [&](auto&& dfs, int i, int j, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> int { if (i >= n) { return 1; } if (f[i][j][k] != -1) { return f[i][j][k]; } - int ans = dfs(dfs, i + 1, j, 0); + int ans = dfs(i + 1, j, 0); if (j == 0) { - ans = (ans + dfs(dfs, i + 1, j + 1, 0)) % mod; + ans = (ans + dfs(i + 1, j + 1, 0)) % mod; } if (k < 2) { - ans = (ans + dfs(dfs, i + 1, j, k + 1)) % mod; + ans = (ans + dfs(i + 1, j, k + 1)) % mod; } return f[i][j][k] = ans; }; - return dfs(dfs, 0, 0, 0); + return dfs(0, 0, 0); } }; ``` diff --git a/solution/0500-0599/0552.Student Attendance Record II/Solution.cpp b/solution/0500-0599/0552.Student Attendance Record II/Solution.cpp index 24fafaa6f3265..abef1a8b966f9 100644 --- a/solution/0500-0599/0552.Student Attendance Record II/Solution.cpp +++ b/solution/0500-0599/0552.Student Attendance Record II/Solution.cpp @@ -4,22 +4,22 @@ class Solution { int f[n][2][3]; memset(f, -1, sizeof(f)); const int mod = 1e9 + 7; - auto dfs = [&](auto&& dfs, int i, int j, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> int { if (i >= n) { return 1; } if (f[i][j][k] != -1) { return f[i][j][k]; } - int ans = dfs(dfs, i + 1, j, 0); + int ans = dfs(i + 1, j, 0); if (j == 0) { - ans = (ans + dfs(dfs, i + 1, j + 1, 0)) % mod; + ans = (ans + dfs(i + 1, j + 1, 0)) % mod; } if (k < 2) { - ans = (ans + dfs(dfs, i + 1, j, k + 1)) % mod; + ans = (ans + dfs(i + 1, j, k + 1)) % mod; } return f[i][j][k] = ans; }; - return dfs(dfs, 0, 0, 0); + return dfs(0, 0, 0); } }; diff --git a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md index 015e941acf437..cbdd3455670a5 100644 --- a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md +++ b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README.md @@ -25,7 +25,7 @@ tags:
 输入: n = 5
 输出: 5
-解释: 
+解释:
 下面列出范围在 [0, 5] 的非负整数与其对应的二进制表示:
 0 : 0
 1 : 1
@@ -171,7 +171,7 @@ public:
         int m = 32 - __builtin_clz(n);
         int f[m][2];
         memset(f, -1, sizeof(f));
-        auto dfs = [&](auto&& dfs, int i, int pre, bool limit) -> int {
+        auto dfs = [&](this auto&& dfs, int i, int pre, bool limit) -> int {
             if (i < 0) {
                 return 1;
             }
@@ -184,14 +184,14 @@ public:
                 if (j && pre) {
                     continue;
                 }
-                ans += dfs(dfs, i - 1, j, limit && j == up);
+                ans += dfs(i - 1, j, limit && j == up);
             }
             if (!limit) {
                 f[i][pre] = ans;
             }
             return ans;
         };
-        return dfs(dfs, m - 1, 0, true);
+        return dfs(m - 1, 0, true);
     }
 };
 ```
diff --git a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README_EN.md b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README_EN.md
index e989af0b602fb..9bdf3595fb173 100644
--- a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README_EN.md	
+++ b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/README_EN.md	
@@ -32,7 +32,7 @@ Here are the non-negative integers <= 5 with their corresponding binary repre
 3 : 11
 4 : 100
 5 : 101
-Among them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule. 
+Among them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule.
 

Example 2:

@@ -170,7 +170,7 @@ public: int m = 32 - __builtin_clz(n); int f[m][2]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int pre, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, int pre, bool limit) -> int { if (i < 0) { return 1; } @@ -183,14 +183,14 @@ public: if (j && pre) { continue; } - ans += dfs(dfs, i - 1, j, limit && j == up); + ans += dfs(i - 1, j, limit && j == up); } if (!limit) { f[i][pre] = ans; } return ans; }; - return dfs(dfs, m - 1, 0, true); + return dfs(m - 1, 0, true); } }; ``` diff --git a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/Solution.cpp b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/Solution.cpp index ada429667657b..12fa2a84eddba 100644 --- a/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/Solution.cpp +++ b/solution/0600-0699/0600.Non-negative Integers without Consecutive Ones/Solution.cpp @@ -4,7 +4,7 @@ class Solution { int m = 32 - __builtin_clz(n); int f[m][2]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int pre, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, int pre, bool limit) -> int { if (i < 0) { return 1; } @@ -17,13 +17,13 @@ class Solution { if (j && pre) { continue; } - ans += dfs(dfs, i - 1, j, limit && j == up); + ans += dfs(i - 1, j, limit && j == up); } if (!limit) { f[i][pre] = ans; } return ans; }; - return dfs(dfs, m - 1, 0, true); + return dfs(m - 1, 0, true); } }; diff --git a/solution/0600-0699/0687.Longest Univalue Path/README.md b/solution/0600-0699/0687.Longest Univalue Path/README.md index 71dcb0acc47e4..4b844bc1a366b 100644 --- a/solution/0600-0699/0687.Longest Univalue Path/README.md +++ b/solution/0600-0699/0687.Longest Univalue Path/README.md @@ -160,18 +160,18 @@ class Solution { public: int longestUnivaluePath(TreeNode* root) { int ans = 0; - auto dfs = [&](auto&& dfs, TreeNode* root) -> int { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> int { if (!root) { return 0; } - int l = dfs(dfs, root->left); - int r = dfs(dfs, root->right); + int l = dfs(root->left); + int r = dfs(root->right); l = root->left && root->left->val == root->val ? l + 1 : 0; r = root->right && root->right->val == root->val ? r + 1 : 0; ans = max(ans, l + r); return max(l, r); }; - dfs(dfs, root); + dfs(root); return ans; } }; diff --git a/solution/0600-0699/0687.Longest Univalue Path/README_EN.md b/solution/0600-0699/0687.Longest Univalue Path/README_EN.md index 07c3dc8337bf3..b6230a638edff 100644 --- a/solution/0600-0699/0687.Longest Univalue Path/README_EN.md +++ b/solution/0600-0699/0687.Longest Univalue Path/README_EN.md @@ -156,18 +156,18 @@ class Solution { public: int longestUnivaluePath(TreeNode* root) { int ans = 0; - auto dfs = [&](auto&& dfs, TreeNode* root) -> int { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> int { if (!root) { return 0; } - int l = dfs(dfs, root->left); - int r = dfs(dfs, root->right); + int l = dfs(root->left); + int r = dfs(root->right); l = root->left && root->left->val == root->val ? l + 1 : 0; r = root->right && root->right->val == root->val ? r + 1 : 0; ans = max(ans, l + r); return max(l, r); }; - dfs(dfs, root); + dfs(root); return ans; } }; diff --git a/solution/0600-0699/0687.Longest Univalue Path/Solution.cpp b/solution/0600-0699/0687.Longest Univalue Path/Solution.cpp index 2d04c10b95811..75ef02835257c 100644 --- a/solution/0600-0699/0687.Longest Univalue Path/Solution.cpp +++ b/solution/0600-0699/0687.Longest Univalue Path/Solution.cpp @@ -13,18 +13,18 @@ class Solution { public: int longestUnivaluePath(TreeNode* root) { int ans = 0; - auto dfs = [&](auto&& dfs, TreeNode* root) -> int { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> int { if (!root) { return 0; } - int l = dfs(dfs, root->left); - int r = dfs(dfs, root->right); + int l = dfs(root->left); + int r = dfs(root->right); l = root->left && root->left->val == root->val ? l + 1 : 0; r = root->right && root->right->val == root->val ? r + 1 : 0; ans = max(ans, l + r); return max(l, r); }; - dfs(dfs, root); + dfs(root); return ans; } }; diff --git a/solution/0700-0799/0746.Min Cost Climbing Stairs/README.md b/solution/0700-0799/0746.Min Cost Climbing Stairs/README.md index 9f5ff416cdbfc..38f80c8c4ea24 100644 --- a/solution/0700-0799/0746.Min Cost Climbing Stairs/README.md +++ b/solution/0700-0799/0746.Min Cost Climbing Stairs/README.md @@ -129,16 +129,16 @@ public: int n = cost.size(); int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } if (f[i] < 0) { - f[i] = cost[i] + min(dfs(dfs, i + 1), dfs(dfs, i + 2)); + f[i] = cost[i] + min(dfs(i + 1), dfs(i + 2)); } return f[i]; }; - return min(dfs(dfs, 0), dfs(dfs, 1)); + return min(dfs(0), dfs(1)); } }; ``` diff --git a/solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md b/solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md index 4708c37382cdb..4dc4fd5a09243 100644 --- a/solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md +++ b/solution/0700-0799/0746.Min Cost Climbing Stairs/README_EN.md @@ -127,16 +127,16 @@ public: int n = cost.size(); int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } if (f[i] < 0) { - f[i] = cost[i] + min(dfs(dfs, i + 1), dfs(dfs, i + 2)); + f[i] = cost[i] + min(dfs(i + 1), dfs(i + 2)); } return f[i]; }; - return min(dfs(dfs, 0), dfs(dfs, 1)); + return min(dfs(0), dfs(1)); } }; ``` diff --git a/solution/0700-0799/0746.Min Cost Climbing Stairs/Solution.cpp b/solution/0700-0799/0746.Min Cost Climbing Stairs/Solution.cpp index a3b6b0cfe14c5..b9f95726d5e8e 100644 --- a/solution/0700-0799/0746.Min Cost Climbing Stairs/Solution.cpp +++ b/solution/0700-0799/0746.Min Cost Climbing Stairs/Solution.cpp @@ -4,15 +4,15 @@ class Solution { int n = cost.size(); int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } if (f[i] < 0) { - f[i] = cost[i] + min(dfs(dfs, i + 1), dfs(dfs, i + 2)); + f[i] = cost[i] + min(dfs(i + 1), dfs(i + 2)); } return f[i]; }; - return min(dfs(dfs, 0), dfs(dfs, 1)); + return min(dfs(0), dfs(1)); } }; diff --git a/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README.md b/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README.md index bcb964c9355fa..cb375475c9819 100644 --- a/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README.md +++ b/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README.md @@ -158,16 +158,16 @@ public: int minDiffInBST(TreeNode* root) { const int inf = 1 << 30; int ans = inf, pre = -inf; - auto dfs = [&](auto&& dfs, TreeNode* root) -> void { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> void { if (!root) { return; } - dfs(dfs, root->left); + dfs(root->left); ans = min(ans, root->val - pre); pre = root->val; - dfs(dfs, root->right); + dfs(root->right); }; - dfs(dfs, root); + dfs(root); return ans; } }; diff --git a/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README_EN.md b/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README_EN.md index 4c207c9590d97..0c7e4f2b1947b 100644 --- a/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README_EN.md +++ b/solution/0700-0799/0783.Minimum Distance Between BST Nodes/README_EN.md @@ -149,16 +149,16 @@ public: int minDiffInBST(TreeNode* root) { const int inf = 1 << 30; int ans = inf, pre = -inf; - auto dfs = [&](auto&& dfs, TreeNode* root) -> void { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> void { if (!root) { return; } - dfs(dfs, root->left); + dfs(root->left); ans = min(ans, root->val - pre); pre = root->val; - dfs(dfs, root->right); + dfs(root->right); }; - dfs(dfs, root); + dfs(root); return ans; } }; diff --git a/solution/0700-0799/0783.Minimum Distance Between BST Nodes/Solution.cpp b/solution/0700-0799/0783.Minimum Distance Between BST Nodes/Solution.cpp index 9857cb328afcc..6a0e9a7baac86 100644 --- a/solution/0700-0799/0783.Minimum Distance Between BST Nodes/Solution.cpp +++ b/solution/0700-0799/0783.Minimum Distance Between BST Nodes/Solution.cpp @@ -14,16 +14,16 @@ class Solution { int minDiffInBST(TreeNode* root) { const int inf = 1 << 30; int ans = inf, pre = -inf; - auto dfs = [&](auto&& dfs, TreeNode* root) -> void { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> void { if (!root) { return; } - dfs(dfs, root->left); + dfs(root->left); ans = min(ans, root->val - pre); pre = root->val; - dfs(dfs, root->right); + dfs(root->right); }; - dfs(dfs, root); + dfs(root); return ans; } -}; \ No newline at end of file +}; diff --git a/solution/0700-0799/0788.Rotated Digits/README.md b/solution/0700-0799/0788.Rotated Digits/README.md index dba29eb20f432..e41150ee0bbd0 100644 --- a/solution/0700-0799/0788.Rotated Digits/README.md +++ b/solution/0700-0799/0788.Rotated Digits/README.md @@ -29,7 +29,7 @@ tags:
输入: 10
 输出: 4
-解释: 
+解释:
 在[1, 10]中有四个好数: 2, 5, 6, 9。
 注意 1 和 10 不是好数, 因为他们在旋转之后不变。
 
@@ -319,7 +319,7 @@ public: int m = s.size(); int f[m][2]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int ok, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, int ok, bool limit) -> int { if (i >= m) { return ok; } @@ -330,9 +330,9 @@ public: int ans = 0; for (int j = 0; j <= up; ++j) { if (j == 0 || j == 1 || j == 8) { - ans += dfs(dfs, i + 1, ok, limit && j == up); + ans += dfs(i + 1, ok, limit && j == up); } else if (j == 2 || j == 5 || j == 6 || j == 9) { - ans += dfs(dfs, i + 1, 1, limit && j == up); + ans += dfs(i + 1, 1, limit && j == up); } } if (!limit) { @@ -340,7 +340,7 @@ public: } return ans; }; - return dfs(dfs, 0, 0, true); + return dfs(0, 0, true); } }; ``` diff --git a/solution/0700-0799/0788.Rotated Digits/README_EN.md b/solution/0700-0799/0788.Rotated Digits/README_EN.md index 4abf402156bab..99c423980a46f 100644 --- a/solution/0700-0799/0788.Rotated Digits/README_EN.md +++ b/solution/0700-0799/0788.Rotated Digits/README_EN.md @@ -338,7 +338,7 @@ public: int m = s.size(); int f[m][2]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int ok, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, int ok, bool limit) -> int { if (i >= m) { return ok; } @@ -349,9 +349,9 @@ public: int ans = 0; for (int j = 0; j <= up; ++j) { if (j == 0 || j == 1 || j == 8) { - ans += dfs(dfs, i + 1, ok, limit && j == up); + ans += dfs(i + 1, ok, limit && j == up); } else if (j == 2 || j == 5 || j == 6 || j == 9) { - ans += dfs(dfs, i + 1, 1, limit && j == up); + ans += dfs(i + 1, 1, limit && j == up); } } if (!limit) { @@ -359,7 +359,7 @@ public: } return ans; }; - return dfs(dfs, 0, 0, true); + return dfs(0, 0, true); } }; ``` diff --git a/solution/0700-0799/0788.Rotated Digits/Solution2.cpp b/solution/0700-0799/0788.Rotated Digits/Solution2.cpp index f4567951dd21a..2f6520586d05c 100644 --- a/solution/0700-0799/0788.Rotated Digits/Solution2.cpp +++ b/solution/0700-0799/0788.Rotated Digits/Solution2.cpp @@ -5,7 +5,7 @@ class Solution { int m = s.size(); int f[m][2]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int ok, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, int ok, bool limit) -> int { if (i >= m) { return ok; } @@ -16,9 +16,9 @@ class Solution { int ans = 0; for (int j = 0; j <= up; ++j) { if (j == 0 || j == 1 || j == 8) { - ans += dfs(dfs, i + 1, ok, limit && j == up); + ans += dfs(i + 1, ok, limit && j == up); } else if (j == 2 || j == 5 || j == 6 || j == 9) { - ans += dfs(dfs, i + 1, 1, limit && j == up); + ans += dfs(i + 1, 1, limit && j == up); } } if (!limit) { @@ -26,6 +26,6 @@ class Solution { } return ans; }; - return dfs(dfs, 0, 0, true); + return dfs(0, 0, true); } }; diff --git a/solution/0800-0899/0813.Largest Sum of Averages/README.md b/solution/0800-0899/0813.Largest Sum of Averages/README.md index 8d0207f40fc92..d230a9446b8fe 100644 --- a/solution/0800-0899/0813.Largest Sum of Averages/README.md +++ b/solution/0800-0899/0813.Largest Sum of Averages/README.md @@ -31,9 +31,9 @@ tags:
 输入: nums = [9,1,2,3,9], k = 3
 输出: 20.00000
-解释: 
-nums 的最优分组是[9], [1, 2, 3], [9]. 得到的分数是 9 + (1 + 2 + 3) / 3 + 9 = 20. 
-我们也可以把 nums 分成[9, 1], [2], [3, 9]. 
+解释:
+nums 的最优分组是[9], [1, 2, 3], [9]. 得到的分数是 9 + (1 + 2 + 3) / 3 + 9 = 20.
+我们也可以把 nums 分成[9, 1], [2], [3, 9].
 这样的分组得到的分数为 5 + 2 + 6 = 13, 但不是最大值.
 
@@ -150,7 +150,7 @@ public: for (int i = 0; i < n; ++i) { s[i + 1] = s[i] + nums[i]; } - auto dfs = [&](auto&& dfs, int i, int k) -> double { + auto dfs = [&](this auto&& dfs, int i, int k) -> double { if (i == n) { return 0; } @@ -162,11 +162,11 @@ public: } double ans = 0; for (int j = i + 1; j < n; ++j) { - ans = max(ans, (s[j] - s[i]) * 1.0 / (j - i) + dfs(dfs, j, k - 1)); + ans = max(ans, (s[j] - s[i]) * 1.0 / (j - i) + dfs(j, k - 1)); } return f[i][k] = ans; }; - return dfs(dfs, 0, k); + return dfs(0, k); } }; ``` diff --git a/solution/0800-0899/0813.Largest Sum of Averages/README_EN.md b/solution/0800-0899/0813.Largest Sum of Averages/README_EN.md index 5b9f70f25a4c6..da12e45899e0f 100644 --- a/solution/0800-0899/0813.Largest Sum of Averages/README_EN.md +++ b/solution/0800-0899/0813.Largest Sum of Averages/README_EN.md @@ -30,7 +30,7 @@ tags:
 Input: nums = [9,1,2,3,9], k = 3
 Output: 20.00000
-Explanation: 
+Explanation:
 The best choice is to partition nums into [9], [1, 2, 3], [9]. The answer is 9 + (1 + 2 + 3) / 3 + 9 = 20.
 We could have also partitioned nums into [9, 1], [2], [3, 9], for example.
 That partition would lead to a score of 5 + 2 + 6 = 13, which is worse.
@@ -146,7 +146,7 @@ public:
         for (int i = 0; i < n; ++i) {
             s[i + 1] = s[i] + nums[i];
         }
-        auto dfs = [&](auto&& dfs, int i, int k) -> double {
+        auto dfs = [&](this auto&& dfs, int i, int k) -> double {
             if (i == n) {
                 return 0;
             }
@@ -158,11 +158,11 @@ public:
             }
             double ans = 0;
             for (int j = i + 1; j < n; ++j) {
-                ans = max(ans, (s[j] - s[i]) * 1.0 / (j - i) + dfs(dfs, j, k - 1));
+                ans = max(ans, (s[j] - s[i]) * 1.0 / (j - i) + dfs(j, k - 1));
             }
             return f[i][k] = ans;
         };
-        return dfs(dfs, 0, k);
+        return dfs(0, k);
     }
 };
 ```
diff --git a/solution/0800-0899/0813.Largest Sum of Averages/Solution.cpp b/solution/0800-0899/0813.Largest Sum of Averages/Solution.cpp
index 77d5123dbd614..bd85e72ed2cc8 100644
--- a/solution/0800-0899/0813.Largest Sum of Averages/Solution.cpp	
+++ b/solution/0800-0899/0813.Largest Sum of Averages/Solution.cpp	
@@ -9,7 +9,7 @@ class Solution {
         for (int i = 0; i < n; ++i) {
             s[i + 1] = s[i] + nums[i];
         }
-        auto dfs = [&](auto&& dfs, int i, int k) -> double {
+        auto dfs = [&](this auto&& dfs, int i, int k) -> double {
             if (i == n) {
                 return 0;
             }
@@ -21,10 +21,10 @@ class Solution {
             }
             double ans = 0;
             for (int j = i + 1; j < n; ++j) {
-                ans = max(ans, (s[j] - s[i]) * 1.0 / (j - i) + dfs(dfs, j, k - 1));
+                ans = max(ans, (s[j] - s[i]) * 1.0 / (j - i) + dfs(j, k - 1));
             }
             return f[i][k] = ans;
         };
-        return dfs(dfs, 0, k);
+        return dfs(0, k);
     }
 };
diff --git a/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README.md b/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README.md
index 400b4f45c2715..568c0573d1edb 100644
--- a/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README.md	
+++ b/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README.md	
@@ -176,12 +176,12 @@ class Solution {
 public:
     TreeNode* subtreeWithAllDeepest(TreeNode* root) {
         using pti = pair;
-        auto dfs = [&](auto&& dfs, TreeNode* root) -> pti {
+        auto dfs = [&](this auto&& dfs, TreeNode* root) -> pti {
             if (!root) {
                 return {nullptr, 0};
             }
-            auto [l, ld] = dfs(dfs, root->left);
-            auto [r, rd] = dfs(dfs, root->right);
+            auto [l, ld] = dfs(root->left);
+            auto [r, rd] = dfs(root->right);
             if (ld > rd) {
                 return {l, ld + 1};
             }
@@ -190,7 +190,7 @@ public:
             }
             return {root, ld + 1};
         };
-        return dfs(dfs, root).first;
+        return dfs(root).first;
     }
 };
 ```
diff --git a/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README_EN.md b/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README_EN.md
index 3af2763735df6..b73d3000bdbb8 100644
--- a/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README_EN.md	
+++ b/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/README_EN.md	
@@ -172,12 +172,12 @@ class Solution {
 public:
     TreeNode* subtreeWithAllDeepest(TreeNode* root) {
         using pti = pair;
-        auto dfs = [&](auto&& dfs, TreeNode* root) -> pti {
+        auto dfs = [&](this auto&& dfs, TreeNode* root) -> pti {
             if (!root) {
                 return {nullptr, 0};
             }
-            auto [l, ld] = dfs(dfs, root->left);
-            auto [r, rd] = dfs(dfs, root->right);
+            auto [l, ld] = dfs(root->left);
+            auto [r, rd] = dfs(root->right);
             if (ld > rd) {
                 return {l, ld + 1};
             }
@@ -186,7 +186,7 @@ public:
             }
             return {root, ld + 1};
         };
-        return dfs(dfs, root).first;
+        return dfs(root).first;
     }
 };
 ```
diff --git a/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/Solution.cpp b/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/Solution.cpp
index c7a0066c01fcd..4a0c4dd3ac997 100644
--- a/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/Solution.cpp	
+++ b/solution/0800-0899/0865.Smallest Subtree with all the Deepest Nodes/Solution.cpp	
@@ -13,12 +13,12 @@ class Solution {
 public:
     TreeNode* subtreeWithAllDeepest(TreeNode* root) {
         using pti = pair;
-        auto dfs = [&](auto&& dfs, TreeNode* root) -> pti {
+        auto dfs = [&](this auto&& dfs, TreeNode* root) -> pti {
             if (!root) {
                 return {nullptr, 0};
             }
-            auto [l, ld] = dfs(dfs, root->left);
-            auto [r, rd] = dfs(dfs, root->right);
+            auto [l, ld] = dfs(root->left);
+            auto [r, rd] = dfs(root->right);
             if (ld > rd) {
                 return {l, ld + 1};
             }
@@ -27,6 +27,6 @@ class Solution {
             }
             return {root, ld + 1};
         };
-        return dfs(dfs, root).first;
+        return dfs(root).first;
     }
 };
diff --git a/solution/0800-0899/0877.Stone Game/README.md b/solution/0800-0899/0877.Stone Game/README.md
index 946fbc853b9c0..8199b3104798d 100644
--- a/solution/0800-0899/0877.Stone Game/README.md	
+++ b/solution/0800-0899/0877.Stone Game/README.md	
@@ -132,16 +132,16 @@ public:
         int n = piles.size();
         int f[n][n];
         memset(f, 0, sizeof(f));
-        auto dfs = [&](auto&& dfs, int i, int j) -> int {
+        auto dfs = [&](this auto&& dfs, int i, int j) -> int {
             if (i > j) {
                 return 0;
             }
             if (f[i][j]) {
                 return f[i][j];
             }
-            return f[i][j] = max(piles[i] - dfs(dfs, i + 1, j), piles[j] - dfs(dfs, i, j - 1));
+            return f[i][j] = max(piles[i] - dfs(i + 1, j), piles[j] - dfs(i, j - 1));
         };
-        return dfs(dfs, 0, n - 1) > 0;
+        return dfs(0, n - 1) > 0;
     }
 };
 ```
diff --git a/solution/0800-0899/0877.Stone Game/README_EN.md b/solution/0800-0899/0877.Stone Game/README_EN.md
index 8127658b93743..e37e499d0855c 100644
--- a/solution/0800-0899/0877.Stone Game/README_EN.md	
+++ b/solution/0800-0899/0877.Stone Game/README_EN.md	
@@ -33,7 +33,7 @@ tags:
 
 Input: piles = [5,3,4,5]
 Output: true
-Explanation: 
+Explanation:
 Alice starts first, and can only take the first 5 or the last 5.
 Say she takes the first 5, so that the row becomes [3, 4, 5].
 If Bob takes 3, then the board is [4, 5], and Alice takes 5 to win with 10 points.
@@ -117,16 +117,16 @@ public:
         int n = piles.size();
         int f[n][n];
         memset(f, 0, sizeof(f));
-        auto dfs = [&](auto&& dfs, int i, int j) -> int {
+        auto dfs = [&](this auto&& dfs, int i, int j) -> int {
             if (i > j) {
                 return 0;
             }
             if (f[i][j]) {
                 return f[i][j];
             }
-            return f[i][j] = max(piles[i] - dfs(dfs, i + 1, j), piles[j] - dfs(dfs, i, j - 1));
+            return f[i][j] = max(piles[i] - dfs(i + 1, j), piles[j] - dfs(i, j - 1));
         };
-        return dfs(dfs, 0, n - 1) > 0;
+        return dfs(0, n - 1) > 0;
     }
 };
 ```
diff --git a/solution/0800-0899/0877.Stone Game/Solution.cpp b/solution/0800-0899/0877.Stone Game/Solution.cpp
index 3435a355f58e0..5ee6a5327dd21 100644
--- a/solution/0800-0899/0877.Stone Game/Solution.cpp	
+++ b/solution/0800-0899/0877.Stone Game/Solution.cpp	
@@ -4,15 +4,15 @@ class Solution {
         int n = piles.size();
         int f[n][n];
         memset(f, 0, sizeof(f));
-        auto dfs = [&](auto&& dfs, int i, int j) -> int {
+        auto dfs = [&](this auto&& dfs, int i, int j) -> int {
             if (i > j) {
                 return 0;
             }
             if (f[i][j]) {
                 return f[i][j];
             }
-            return f[i][j] = max(piles[i] - dfs(dfs, i + 1, j), piles[j] - dfs(dfs, i, j - 1));
+            return f[i][j] = max(piles[i] - dfs(i + 1, j), piles[j] - dfs(i, j - 1));
         };
-        return dfs(dfs, 0, n - 1) > 0;
+        return dfs(0, n - 1) > 0;
     }
-};
\ No newline at end of file
+};
diff --git a/solution/0800-0899/0887.Super Egg Drop/README.md b/solution/0800-0899/0887.Super Egg Drop/README.md
index 39d3803790ed8..b37dea42446b4 100644
--- a/solution/0800-0899/0887.Super Egg Drop/README.md	
+++ b/solution/0800-0899/0887.Super Egg Drop/README.md	
@@ -25,7 +25,6 @@ tags:
 

每次操作,你可以取一枚没有碎的鸡蛋并把它从任一楼层 x 扔下(满足 1 <= x <= n)。如果鸡蛋碎了,你就不能再次使用它。如果某枚鸡蛋扔下后没有摔碎,则可以在之后的操作中 重复使用 这枚鸡蛋。

请你计算并返回要确定 f 确切的值最小操作次数 是多少?

示例 1:

@@ -33,10 +32,10 @@ tags: 输入:k = 1, n = 2 输出:2 解释: -鸡蛋从 1 楼掉落。如果它碎了,肯定能得出 f = 0 。 -否则,鸡蛋从 2 楼掉落。如果它碎了,肯定能得出 f = 1 。 -如果它没碎,那么肯定能得出 f = 2 。 -因此,在最坏的情况下我们需要移动 2 次以确定 f 是多少。 +鸡蛋从 1 楼掉落。如果它碎了,肯定能得出 f = 0 。 +否则,鸡蛋从 2 楼掉落。如果它碎了,肯定能得出 f = 1 。 +如果它没碎,那么肯定能得出 f = 2 。 +因此,在最坏的情况下我们需要移动 2 次以确定 f 是多少。

示例 2:

@@ -158,7 +157,7 @@ public: int superEggDrop(int k, int n) { int f[n + 1][k + 1]; memset(f, 0, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int j) -> int { + auto dfs = [&](this auto&& dfs, int i, int j) -> int { if (i < 1) { return 0; } @@ -171,17 +170,17 @@ public: int l = 1, r = i; while (l < r) { int mid = (l + r + 1) >> 1; - int a = dfs(dfs, mid - 1, j - 1); - int b = dfs(dfs, i - mid, j); + int a = dfs(mid - 1, j - 1); + int b = dfs(i - mid, j); if (a <= b) { l = mid; } else { r = mid - 1; } } - return f[i][j] = max(dfs(dfs, l - 1, j - 1), dfs(dfs, i - l, j)) + 1; + return f[i][j] = max(dfs(l - 1, j - 1), dfs(i - l, j)) + 1; }; - return dfs(dfs, n, k); + return dfs(n, k); } }; ``` diff --git a/solution/0800-0899/0887.Super Egg Drop/README_EN.md b/solution/0800-0899/0887.Super Egg Drop/README_EN.md index 3b1c934196d79..2c96516bf66fb 100644 --- a/solution/0800-0899/0887.Super Egg Drop/README_EN.md +++ b/solution/0800-0899/0887.Super Egg Drop/README_EN.md @@ -141,7 +141,7 @@ public: int superEggDrop(int k, int n) { int f[n + 1][k + 1]; memset(f, 0, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int j) -> int { + auto dfs = [&](this auto&& dfs, int i, int j) -> int { if (i < 1) { return 0; } @@ -154,17 +154,17 @@ public: int l = 1, r = i; while (l < r) { int mid = (l + r + 1) >> 1; - int a = dfs(dfs, mid - 1, j - 1); - int b = dfs(dfs, i - mid, j); + int a = dfs(mid - 1, j - 1); + int b = dfs(i - mid, j); if (a <= b) { l = mid; } else { r = mid - 1; } } - return f[i][j] = max(dfs(dfs, l - 1, j - 1), dfs(dfs, i - l, j)) + 1; + return f[i][j] = max(dfs(l - 1, j - 1), dfs(i - l, j)) + 1; }; - return dfs(dfs, n, k); + return dfs(n, k); } }; ``` diff --git a/solution/0800-0899/0887.Super Egg Drop/Solution.cpp b/solution/0800-0899/0887.Super Egg Drop/Solution.cpp index 4fc7571df685d..eb970ff11edbc 100644 --- a/solution/0800-0899/0887.Super Egg Drop/Solution.cpp +++ b/solution/0800-0899/0887.Super Egg Drop/Solution.cpp @@ -3,7 +3,7 @@ class Solution { int superEggDrop(int k, int n) { int f[n + 1][k + 1]; memset(f, 0, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int j) -> int { + auto dfs = [&](this auto&& dfs, int i, int j) -> int { if (i < 1) { return 0; } @@ -16,16 +16,16 @@ class Solution { int l = 1, r = i; while (l < r) { int mid = (l + r + 1) >> 1; - int a = dfs(dfs, mid - 1, j - 1); - int b = dfs(dfs, i - mid, j); + int a = dfs(mid - 1, j - 1); + int b = dfs(i - mid, j); if (a <= b) { l = mid; } else { r = mid - 1; } } - return f[i][j] = max(dfs(dfs, l - 1, j - 1), dfs(dfs, i - l, j)) + 1; + return f[i][j] = max(dfs(l - 1, j - 1), dfs(i - l, j)) + 1; }; - return dfs(dfs, n, k); + return dfs(n, k); } }; diff --git a/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README.md b/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README.md index 1514aaf153ce8..dac680c589dc6 100644 --- a/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README.md +++ b/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README.md @@ -200,7 +200,7 @@ public: int m = s.size(); int f[m]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, bool lead, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, bool lead, bool limit) -> int { if (i >= m) { return lead ? 0 : 1; } @@ -211,9 +211,9 @@ public: int ans = 0; for (int j = 0; j <= up; ++j) { if (j == 0 && lead) { - ans += dfs(dfs, i + 1, true, limit && j == up); + ans += dfs(i + 1, true, limit && j == up); } else if (nums.count(j)) { - ans += dfs(dfs, i + 1, false, limit && j == up); + ans += dfs(i + 1, false, limit && j == up); } } if (!lead && !limit) { @@ -221,7 +221,7 @@ public: } return ans; }; - return dfs(dfs, 0, true, true); + return dfs(0, true, true); } }; ``` diff --git a/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README_EN.md b/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README_EN.md index 256228d5c2851..3c34a3fb28dc4 100644 --- a/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README_EN.md +++ b/solution/0900-0999/0902.Numbers At Most N Given Digit Set/README_EN.md @@ -198,7 +198,7 @@ public: int m = s.size(); int f[m]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, bool lead, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, bool lead, bool limit) -> int { if (i >= m) { return lead ? 0 : 1; } @@ -209,9 +209,9 @@ public: int ans = 0; for (int j = 0; j <= up; ++j) { if (j == 0 && lead) { - ans += dfs(dfs, i + 1, true, limit && j == up); + ans += dfs(i + 1, true, limit && j == up); } else if (nums.count(j)) { - ans += dfs(dfs, i + 1, false, limit && j == up); + ans += dfs(i + 1, false, limit && j == up); } } if (!lead && !limit) { @@ -219,7 +219,7 @@ public: } return ans; }; - return dfs(dfs, 0, true, true); + return dfs(0, true, true); } }; ``` diff --git a/solution/0900-0999/0902.Numbers At Most N Given Digit Set/Solution.cpp b/solution/0900-0999/0902.Numbers At Most N Given Digit Set/Solution.cpp index fe7fc4cda0907..e43a956ee6ed3 100644 --- a/solution/0900-0999/0902.Numbers At Most N Given Digit Set/Solution.cpp +++ b/solution/0900-0999/0902.Numbers At Most N Given Digit Set/Solution.cpp @@ -9,7 +9,7 @@ class Solution { int m = s.size(); int f[m]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, bool lead, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, bool lead, bool limit) -> int { if (i >= m) { return lead ? 0 : 1; } @@ -20,9 +20,9 @@ class Solution { int ans = 0; for (int j = 0; j <= up; ++j) { if (j == 0 && lead) { - ans += dfs(dfs, i + 1, true, limit && j == up); + ans += dfs(i + 1, true, limit && j == up); } else if (nums.count(j)) { - ans += dfs(dfs, i + 1, false, limit && j == up); + ans += dfs(i + 1, false, limit && j == up); } } if (!lead && !limit) { @@ -30,6 +30,6 @@ class Solution { } return ans; }; - return dfs(dfs, 0, true, true); + return dfs(0, true, true); } -}; \ No newline at end of file +}; diff --git a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README.md b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README.md index 0f0c134573d43..9ae322c640b2c 100644 --- a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README.md +++ b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README.md @@ -141,21 +141,21 @@ public: vector numsSameConsecDiff(int n, int k) { vector ans; int boundary = pow(10, n - 1); - auto dfs = [&](auto&& dfs, int x) { + auto dfs = [&](this auto&& dfs, int x) { if (x >= boundary) { ans.push_back(x); return; } int last = x % 10; if (last + k < 10) { - dfs(dfs, x * 10 + last + k); + dfs(x * 10 + last + k); } if (k != 0 && last - k >= 0) { - dfs(dfs, x * 10 + last - k); + dfs(x * 10 + last - k); } }; for (int i = 1; i < 10; ++i) { - dfs(dfs, i); + dfs(i); } return ans; } diff --git a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README_EN.md b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README_EN.md index df81fe1180a94..45894e49af604 100644 --- a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README_EN.md +++ b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/README_EN.md @@ -124,21 +124,21 @@ public: vector numsSameConsecDiff(int n, int k) { vector ans; int boundary = pow(10, n - 1); - auto dfs = [&](auto&& dfs, int x) { + auto dfs = [&](this auto&& dfs, int x) { if (x >= boundary) { ans.push_back(x); return; } int last = x % 10; if (last + k < 10) { - dfs(dfs, x * 10 + last + k); + dfs(x * 10 + last + k); } if (k != 0 && last - k >= 0) { - dfs(dfs, x * 10 + last - k); + dfs(x * 10 + last - k); } }; for (int i = 1; i < 10; ++i) { - dfs(dfs, i); + dfs(i); } return ans; } diff --git a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.cpp b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.cpp index 93d2a7e666196..a6d52820eb609 100644 --- a/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.cpp +++ b/solution/0900-0999/0967.Numbers With Same Consecutive Differences/Solution.cpp @@ -3,21 +3,21 @@ class Solution { vector numsSameConsecDiff(int n, int k) { vector ans; int boundary = pow(10, n - 1); - auto dfs = [&](auto&& dfs, int x) { + auto dfs = [&](this auto&& dfs, int x) { if (x >= boundary) { ans.push_back(x); return; } int last = x % 10; if (last + k < 10) { - dfs(dfs, x * 10 + last + k); + dfs(x * 10 + last + k); } if (k != 0 && last - k >= 0) { - dfs(dfs, x * 10 + last - k); + dfs(x * 10 + last - k); } }; for (int i = 1; i < 10; ++i) { - dfs(dfs, i); + dfs(i); } return ans; } diff --git a/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README.md b/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README.md index 8078632c3ee3b..863e149332f3f 100644 --- a/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README.md +++ b/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README.md @@ -166,7 +166,7 @@ class Solution { class Solution { public: TreeNode* bstFromPreorder(vector& preorder) { - auto dfs = [&](auto&& dfs, int i, int j) -> TreeNode* { + auto dfs = [&](this auto&& dfs, int i, int j) -> TreeNode* { if (i > j) { return nullptr; } @@ -180,11 +180,11 @@ public: l = mid + 1; } } - root->left = dfs(dfs, i + 1, l - 1); - root->right = dfs(dfs, l, j); + root->left = dfs(i + 1, l - 1); + root->right = dfs(l, j); return root; }; - return dfs(dfs, 0, preorder.size() - 1); + return dfs(0, preorder.size() - 1); } }; ``` diff --git a/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README_EN.md b/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README_EN.md index 9bf02ca4fbe11..f4124fdc6f57d 100644 --- a/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README_EN.md +++ b/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/README_EN.md @@ -160,7 +160,7 @@ class Solution { class Solution { public: TreeNode* bstFromPreorder(vector& preorder) { - auto dfs = [&](auto&& dfs, int i, int j) -> TreeNode* { + auto dfs = [&](this auto&& dfs, int i, int j) -> TreeNode* { if (i > j) { return nullptr; } @@ -174,11 +174,11 @@ public: l = mid + 1; } } - root->left = dfs(dfs, i + 1, l - 1); - root->right = dfs(dfs, l, j); + root->left = dfs(i + 1, l - 1); + root->right = dfs(l, j); return root; }; - return dfs(dfs, 0, preorder.size() - 1); + return dfs(0, preorder.size() - 1); } }; ``` diff --git a/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/Solution.cpp b/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/Solution.cpp index dc898630b99c0..5b511063bcf35 100644 --- a/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/Solution.cpp +++ b/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/Solution.cpp @@ -12,7 +12,7 @@ class Solution { public: TreeNode* bstFromPreorder(vector& preorder) { - auto dfs = [&](auto&& dfs, int i, int j) -> TreeNode* { + auto dfs = [&](this auto&& dfs, int i, int j) -> TreeNode* { if (i > j) { return nullptr; } @@ -26,10 +26,10 @@ class Solution { l = mid + 1; } } - root->left = dfs(dfs, i + 1, l - 1); - root->right = dfs(dfs, l, j); + root->left = dfs(i + 1, l - 1); + root->right = dfs(l, j); return root; }; - return dfs(dfs, 0, preorder.size() - 1); + return dfs(0, preorder.size() - 1); } }; diff --git a/solution/1000-1099/1012.Numbers With Repeated Digits/README.md b/solution/1000-1099/1012.Numbers With Repeated Digits/README.md index 5db025d60d7f7..9fc60ac18ff92 100644 --- a/solution/1000-1099/1012.Numbers With Repeated Digits/README.md +++ b/solution/1000-1099/1012.Numbers With Repeated Digits/README.md @@ -169,7 +169,7 @@ public: int m = s.size(); int f[m][1 << 10]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int mask, bool lead, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, int mask, bool lead, bool limit) -> int { if (i >= m) { return lead ^ 1; } @@ -180,9 +180,9 @@ public: int ans = 0; for (int j = 0; j <= up; ++j) { if (lead && j == 0) { - ans += dfs(dfs, i + 1, mask, true, limit && j == up); + ans += dfs(i + 1, mask, true, limit && j == up); } else if (mask >> j & 1 ^ 1) { - ans += dfs(dfs, i + 1, mask | (1 << j), false, limit && j == up); + ans += dfs(i + 1, mask | (1 << j), false, limit && j == up); } } if (!lead && !limit) { @@ -190,7 +190,7 @@ public: } return ans; }; - return n - dfs(dfs, 0, 0, true, true); + return n - dfs(0, 0, true, true); } }; ``` diff --git a/solution/1000-1099/1012.Numbers With Repeated Digits/README_EN.md b/solution/1000-1099/1012.Numbers With Repeated Digits/README_EN.md index f4d48ffe014b0..bae33179a47e2 100644 --- a/solution/1000-1099/1012.Numbers With Repeated Digits/README_EN.md +++ b/solution/1000-1099/1012.Numbers With Repeated Digits/README_EN.md @@ -167,7 +167,7 @@ public: int m = s.size(); int f[m][1 << 10]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int mask, bool lead, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, int mask, bool lead, bool limit) -> int { if (i >= m) { return lead ^ 1; } @@ -178,9 +178,9 @@ public: int ans = 0; for (int j = 0; j <= up; ++j) { if (lead && j == 0) { - ans += dfs(dfs, i + 1, mask, true, limit && j == up); + ans += dfs(i + 1, mask, true, limit && j == up); } else if (mask >> j & 1 ^ 1) { - ans += dfs(dfs, i + 1, mask | (1 << j), false, limit && j == up); + ans += dfs(i + 1, mask | (1 << j), false, limit && j == up); } } if (!lead && !limit) { @@ -188,7 +188,7 @@ public: } return ans; }; - return n - dfs(dfs, 0, 0, true, true); + return n - dfs(0, 0, true, true); } }; ``` diff --git a/solution/1000-1099/1012.Numbers With Repeated Digits/Solution.cpp b/solution/1000-1099/1012.Numbers With Repeated Digits/Solution.cpp index 332d9b47cb828..d1d925bf0f3bd 100644 --- a/solution/1000-1099/1012.Numbers With Repeated Digits/Solution.cpp +++ b/solution/1000-1099/1012.Numbers With Repeated Digits/Solution.cpp @@ -5,7 +5,7 @@ class Solution { int m = s.size(); int f[m][1 << 10]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int mask, bool lead, bool limit) -> int { + auto dfs = [&](this auto&& dfs, int i, int mask, bool lead, bool limit) -> int { if (i >= m) { return lead ^ 1; } @@ -16,9 +16,9 @@ class Solution { int ans = 0; for (int j = 0; j <= up; ++j) { if (lead && j == 0) { - ans += dfs(dfs, i + 1, mask, true, limit && j == up); + ans += dfs(i + 1, mask, true, limit && j == up); } else if (mask >> j & 1 ^ 1) { - ans += dfs(dfs, i + 1, mask | (1 << j), false, limit && j == up); + ans += dfs(i + 1, mask | (1 << j), false, limit && j == up); } } if (!lead && !limit) { @@ -26,6 +26,6 @@ class Solution { } return ans; }; - return n - dfs(dfs, 0, 0, true, true); + return n - dfs(0, 0, true, true); } -}; \ No newline at end of file +}; diff --git a/solution/1200-1299/1245.Tree Diameter/README.md b/solution/1200-1299/1245.Tree Diameter/README.md index 9882aaf214732..dc1f3dc6591df 100644 --- a/solution/1200-1299/1245.Tree Diameter/README.md +++ b/solution/1200-1299/1245.Tree Diameter/README.md @@ -153,10 +153,10 @@ public: g[b].push_back(a); } int ans = 0, a = 0; - auto dfs = [&](auto&& dfs, int i, int fa, int t) -> void { + auto dfs = [&](this auto&& dfs, int i, int fa, int t) -> void { for (int j : g[i]) { if (j != fa) { - dfs(dfs, j, i, t + 1); + dfs(j, i, t + 1); } } if (ans < t) { @@ -164,8 +164,8 @@ public: a = i; } }; - dfs(dfs, 0, -1, 0); - dfs(dfs, a, -1, 0); + dfs(0, -1, 0); + dfs(a, -1, 0); return ans; } }; diff --git a/solution/1200-1299/1245.Tree Diameter/README_EN.md b/solution/1200-1299/1245.Tree Diameter/README_EN.md index 1c468310a4631..bba21899a7f95 100644 --- a/solution/1200-1299/1245.Tree Diameter/README_EN.md +++ b/solution/1200-1299/1245.Tree Diameter/README_EN.md @@ -147,10 +147,10 @@ public: g[b].push_back(a); } int ans = 0, a = 0; - auto dfs = [&](auto&& dfs, int i, int fa, int t) -> void { + auto dfs = [&](this auto&& dfs, int i, int fa, int t) -> void { for (int j : g[i]) { if (j != fa) { - dfs(dfs, j, i, t + 1); + dfs(j, i, t + 1); } } if (ans < t) { @@ -158,8 +158,8 @@ public: a = i; } }; - dfs(dfs, 0, -1, 0); - dfs(dfs, a, -1, 0); + dfs(0, -1, 0); + dfs(a, -1, 0); return ans; } }; diff --git a/solution/1200-1299/1245.Tree Diameter/Solution.cpp b/solution/1200-1299/1245.Tree Diameter/Solution.cpp index 800f0604accc4..d6125f3584502 100644 --- a/solution/1200-1299/1245.Tree Diameter/Solution.cpp +++ b/solution/1200-1299/1245.Tree Diameter/Solution.cpp @@ -9,10 +9,10 @@ class Solution { g[b].push_back(a); } int ans = 0, a = 0; - auto dfs = [&](auto&& dfs, int i, int fa, int t) -> void { + auto dfs = [&](this auto&& dfs, int i, int fa, int t) -> void { for (int j : g[i]) { if (j != fa) { - dfs(dfs, j, i, t + 1); + dfs(j, i, t + 1); } } if (ans < t) { @@ -20,8 +20,8 @@ class Solution { a = i; } }; - dfs(dfs, 0, -1, 0); - dfs(dfs, a, -1, 0); + dfs(0, -1, 0); + dfs(a, -1, 0); return ans; } -}; \ No newline at end of file +}; diff --git a/solution/1300-1399/1302.Deepest Leaves Sum/README.md b/solution/1300-1399/1302.Deepest Leaves Sum/README.md index 1cf9d278320df..a24eb4148ba55 100644 --- a/solution/1300-1399/1302.Deepest Leaves Sum/README.md +++ b/solution/1300-1399/1302.Deepest Leaves Sum/README.md @@ -385,7 +385,7 @@ class Solution { public: int deepestLeavesSum(TreeNode* root) { int mx = 0, ans = 0; - auto dfs = [&](auto&& dfs, TreeNode* root, int i) { + auto dfs = [&](this auto&& dfs, TreeNode* root, int i) { if (!root) { return; } @@ -395,10 +395,10 @@ public: mx = i; ans = root->val; } - dfs(dfs, root->left, i + 1); - dfs(dfs, root->right, i + 1); + dfs(root->left, i + 1); + dfs(root->right, i + 1); }; - dfs(dfs, root, 1); + dfs(root, 1); return ans; } }; diff --git a/solution/1300-1399/1302.Deepest Leaves Sum/README_EN.md b/solution/1300-1399/1302.Deepest Leaves Sum/README_EN.md index fd417be28f82a..8453de8b3b9f5 100644 --- a/solution/1300-1399/1302.Deepest Leaves Sum/README_EN.md +++ b/solution/1300-1399/1302.Deepest Leaves Sum/README_EN.md @@ -381,7 +381,7 @@ class Solution { public: int deepestLeavesSum(TreeNode* root) { int mx = 0, ans = 0; - auto dfs = [&](auto&& dfs, TreeNode* root, int i) { + auto dfs = [&](this auto&& dfs, TreeNode* root, int i) { if (!root) { return; } @@ -391,10 +391,10 @@ public: mx = i; ans = root->val; } - dfs(dfs, root->left, i + 1); - dfs(dfs, root->right, i + 1); + dfs(root->left, i + 1); + dfs(root->right, i + 1); }; - dfs(dfs, root, 1); + dfs(root, 1); return ans; } }; diff --git a/solution/1300-1399/1302.Deepest Leaves Sum/Solution2.cpp b/solution/1300-1399/1302.Deepest Leaves Sum/Solution2.cpp index e98c07bcc3aca..2bc93f264e51c 100644 --- a/solution/1300-1399/1302.Deepest Leaves Sum/Solution2.cpp +++ b/solution/1300-1399/1302.Deepest Leaves Sum/Solution2.cpp @@ -13,7 +13,7 @@ class Solution { public: int deepestLeavesSum(TreeNode* root) { int mx = 0, ans = 0; - auto dfs = [&](auto&& dfs, TreeNode* root, int i) { + auto dfs = [&](this auto&& dfs, TreeNode* root, int i) { if (!root) { return; } @@ -23,10 +23,10 @@ class Solution { mx = i; ans = root->val; } - dfs(dfs, root->left, i + 1); - dfs(dfs, root->right, i + 1); + dfs(root->left, i + 1); + dfs(root->right, i + 1); }; - dfs(dfs, root, 1); + dfs(root, 1); return ans; } }; diff --git a/solution/1400-1499/1469.Find All The Lonely Nodes/README.md b/solution/1400-1499/1469.Find All The Lonely Nodes/README.md index 15fa8d0ecd445..eccb0513baf4a 100644 --- a/solution/1400-1499/1469.Find All The Lonely Nodes/README.md +++ b/solution/1400-1499/1469.Find All The Lonely Nodes/README.md @@ -173,7 +173,7 @@ class Solution { public: vector getLonelyNodes(TreeNode* root) { vector ans; - auto dfs = [&](auto&& dfs, TreeNode* root) { + auto dfs = [&](this auto&& dfs, TreeNode* root) { if (!root || (root->left == root->right)) { return; } @@ -183,10 +183,10 @@ public: if (!root->right) { ans.push_back(root->left->val); } - dfs(dfs, root->left); - dfs(dfs, root->right); + dfs(root->left); + dfs(root->right); }; - dfs(dfs, root); + dfs(root); return ans; } }; diff --git a/solution/1400-1499/1469.Find All The Lonely Nodes/README_EN.md b/solution/1400-1499/1469.Find All The Lonely Nodes/README_EN.md index c89cf1c99af6c..3371ea1c22f1a 100644 --- a/solution/1400-1499/1469.Find All The Lonely Nodes/README_EN.md +++ b/solution/1400-1499/1469.Find All The Lonely Nodes/README_EN.md @@ -166,7 +166,7 @@ class Solution { public: vector getLonelyNodes(TreeNode* root) { vector ans; - auto dfs = [&](auto&& dfs, TreeNode* root) { + auto dfs = [&](this auto&& dfs, TreeNode* root) { if (!root || (root->left == root->right)) { return; } @@ -176,10 +176,10 @@ public: if (!root->right) { ans.push_back(root->left->val); } - dfs(dfs, root->left); - dfs(dfs, root->right); + dfs(root->left); + dfs(root->right); }; - dfs(dfs, root); + dfs(root); return ans; } }; diff --git a/solution/1400-1499/1469.Find All The Lonely Nodes/Solution.cpp b/solution/1400-1499/1469.Find All The Lonely Nodes/Solution.cpp index bd7829428e46d..0cf5df7fbbe76 100644 --- a/solution/1400-1499/1469.Find All The Lonely Nodes/Solution.cpp +++ b/solution/1400-1499/1469.Find All The Lonely Nodes/Solution.cpp @@ -13,7 +13,7 @@ class Solution { public: vector getLonelyNodes(TreeNode* root) { vector ans; - auto dfs = [&](auto&& dfs, TreeNode* root) { + auto dfs = [&](this auto&& dfs, TreeNode* root) { if (!root || (root->left == root->right)) { return; } @@ -23,10 +23,10 @@ class Solution { if (!root->right) { ans.push_back(root->left->val); } - dfs(dfs, root->left); - dfs(dfs, root->right); + dfs(root->left); + dfs(root->right); }; - dfs(dfs, root); + dfs(root); return ans; } }; diff --git a/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README.md b/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README.md index bfb0df5c6933b..2a5ef80e5fc38 100644 --- a/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README.md +++ b/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README.md @@ -149,7 +149,7 @@ class Solution { class Solution { public: bool splitString(string s) { - auto dfs = [&](auto&& dfs, int i, long long x) -> bool { + auto dfs = [&](this auto&& dfs, int i, long long x) -> bool { if (i >= s.size()) { return true; } @@ -160,13 +160,13 @@ public: if (y > 1e10) { break; } - if ((x < 0 || x - y == 1) && dfs(dfs, j + 1, y)) { + if ((x < 0 || x - y == 1) && dfs(j + 1, y)) { return true; } } return false; }; - return dfs(dfs, 0, -1); + return dfs(0, -1); } }; ``` diff --git a/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README_EN.md b/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README_EN.md index f50ef0539ec34..30dc658f3ac31 100644 --- a/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README_EN.md +++ b/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/README_EN.md @@ -139,7 +139,7 @@ class Solution { class Solution { public: bool splitString(string s) { - auto dfs = [&](auto&& dfs, int i, long long x) -> bool { + auto dfs = [&](this auto&& dfs, int i, long long x) -> bool { if (i >= s.size()) { return true; } @@ -150,13 +150,13 @@ public: if (y > 1e10) { break; } - if ((x < 0 || x - y == 1) && dfs(dfs, j + 1, y)) { + if ((x < 0 || x - y == 1) && dfs(j + 1, y)) { return true; } } return false; }; - return dfs(dfs, 0, -1); + return dfs(0, -1); } }; ``` diff --git a/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/Solution.cpp b/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/Solution.cpp index 45173c4a7cdd5..221ccd6dd9f46 100644 --- a/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/Solution.cpp +++ b/solution/1800-1899/1849.Splitting a String Into Descending Consecutive Values/Solution.cpp @@ -1,7 +1,7 @@ class Solution { public: bool splitString(string s) { - auto dfs = [&](auto&& dfs, int i, long long x) -> bool { + auto dfs = [&](this auto&& dfs, int i, long long x) -> bool { if (i >= s.size()) { return true; } @@ -12,12 +12,12 @@ class Solution { if (y > 1e10) { break; } - if ((x < 0 || x - y == 1) && dfs(dfs, j + 1, y)) { + if ((x < 0 || x - y == 1) && dfs(j + 1, y)) { return true; } } return false; }; - return dfs(dfs, 0, -1); + return dfs(0, -1); } }; diff --git a/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README.md b/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README.md index 6638a4ebf040c..77eeec3ede297 100644 --- a/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README.md +++ b/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README.md @@ -182,7 +182,7 @@ public: int n = s.size() - 1; int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (s[n] - s[i] + n - i - 1 <= k) { return 0; } @@ -192,11 +192,11 @@ public: int ans = INT_MAX; for (int j = i + 1; j < n && s[j] - s[i] + j - i - 1 <= k; ++j) { int m = s[j] - s[i] + j - i - 1; - ans = min(ans, dfs(dfs, j) + (k - m) * (k - m)); + ans = min(ans, dfs(j) + (k - m) * (k - m)); } return f[i] = ans; }; - return dfs(dfs, 0); + return dfs(0); } }; ``` diff --git a/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README_EN.md b/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README_EN.md index 60ca5691d154a..9a0b87aedd317 100644 --- a/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README_EN.md +++ b/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/README_EN.md @@ -181,7 +181,7 @@ public: int n = s.size() - 1; int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (s[n] - s[i] + n - i - 1 <= k) { return 0; } @@ -191,11 +191,11 @@ public: int ans = INT_MAX; for (int j = i + 1; j < n && s[j] - s[i] + j - i - 1 <= k; ++j) { int m = s[j] - s[i] + j - i - 1; - ans = min(ans, dfs(dfs, j) + (k - m) * (k - m)); + ans = min(ans, dfs(j) + (k - m) * (k - m)); } return f[i] = ans; }; - return dfs(dfs, 0); + return dfs(0); } }; ``` diff --git a/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/Solution.cpp b/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/Solution.cpp index 49ab761d99840..fa2d12945146f 100644 --- a/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/Solution.cpp +++ b/solution/2000-2099/2052.Minimum Cost to Separate Sentence Into Rows/Solution.cpp @@ -10,7 +10,7 @@ class Solution { int n = s.size() - 1; int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (s[n] - s[i] + n - i - 1 <= k) { return 0; } @@ -20,10 +20,10 @@ class Solution { int ans = INT_MAX; for (int j = i + 1; j < n && s[j] - s[i] + j - i - 1 <= k; ++j) { int m = s[j] - s[i] + j - i - 1; - ans = min(ans, dfs(dfs, j) + (k - m) * (k - m)); + ans = min(ans, dfs(j) + (k - m) * (k - m)); } return f[i] = ans; }; - return dfs(dfs, 0); + return dfs(0); } }; diff --git a/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md b/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md index 67637e8b373df..7fcc8268e9af7 100644 --- a/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md +++ b/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README.md @@ -369,7 +369,7 @@ public: return queenDirs; }; - auto dfs = [&](auto&& dfs, int i) -> void { + auto dfs = [&](this auto&& dfs, int i) -> void { if (i >= n) { ans++; return; @@ -381,7 +381,7 @@ public: end[i] = {x, y, 0}; if (checkStop(i, x, y, 0)) { - dfs(dfs, i + 1); + dfs(i + 1); } const int(*dirs)[2] = getDirs(pieces[i]); @@ -396,7 +396,7 @@ public: dist[i][nx][ny] = nt; end[i] = {nx, ny, nt}; if (checkStop(i, nx, ny, nt)) { - dfs(dfs, i + 1); + dfs(i + 1); } nx += dirs[d][0]; ny += dirs[d][1]; @@ -405,7 +405,7 @@ public: } }; - dfs(dfs, 0); + dfs(0); return ans; } }; diff --git a/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README_EN.md b/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README_EN.md index 9f32a7e97ab97..3860e01cc2ec6 100644 --- a/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README_EN.md +++ b/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/README_EN.md @@ -330,7 +330,7 @@ public: return queenDirs; }; - auto dfs = [&](auto&& dfs, int i) -> void { + auto dfs = [&](this auto&& dfs, int i) -> void { if (i >= n) { ans++; return; @@ -342,7 +342,7 @@ public: end[i] = {x, y, 0}; if (checkStop(i, x, y, 0)) { - dfs(dfs, i + 1); + dfs(i + 1); } const int(*dirs)[2] = getDirs(pieces[i]); @@ -357,7 +357,7 @@ public: dist[i][nx][ny] = nt; end[i] = {nx, ny, nt}; if (checkStop(i, nx, ny, nt)) { - dfs(dfs, i + 1); + dfs(i + 1); } nx += dirs[d][0]; ny += dirs[d][1]; @@ -366,7 +366,7 @@ public: } }; - dfs(dfs, 0); + dfs(0); return ans; } }; diff --git a/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/Solution.cpp b/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/Solution.cpp index 9ff847a0a66a7..fc25433aa8bfa 100644 --- a/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/Solution.cpp +++ b/solution/2000-2099/2056.Number of Valid Move Combinations On Chessboard/Solution.cpp @@ -56,7 +56,7 @@ class Solution { return queenDirs; }; - auto dfs = [&](auto&& dfs, int i) -> void { + auto dfs = [&](this auto&& dfs, int i) -> void { if (i >= n) { ans++; return; @@ -68,7 +68,7 @@ class Solution { end[i] = {x, y, 0}; if (checkStop(i, x, y, 0)) { - dfs(dfs, i + 1); + dfs(i + 1); } const int(*dirs)[2] = getDirs(pieces[i]); @@ -83,7 +83,7 @@ class Solution { dist[i][nx][ny] = nt; end[i] = {nx, ny, nt}; if (checkStop(i, nx, ny, nt)) { - dfs(dfs, i + 1); + dfs(i + 1); } nx += dirs[d][0]; ny += dirs[d][1]; @@ -92,7 +92,7 @@ class Solution { } }; - dfs(dfs, 0); + dfs(0); return ans; } }; diff --git a/solution/2000-2099/2065.Maximum Path Quality of a Graph/README.md b/solution/2000-2099/2065.Maximum Path Quality of a Graph/README.md index 8fdfc6e964d9b..63302e3d2cddb 100644 --- a/solution/2000-2099/2065.Maximum Path Quality of a Graph/README.md +++ b/solution/2000-2099/2065.Maximum Path Quality of a Graph/README.md @@ -215,23 +215,23 @@ public: memset(vis, false, sizeof(vis)); vis[0] = true; int ans = 0; - auto dfs = [&](auto&& dfs, int u, int cost, int value) -> void { + auto dfs = [&](this auto&& dfs, int u, int cost, int value) -> void { if (u == 0) { ans = max(ans, value); } for (auto& [v, t] : g[u]) { if (cost + t <= maxTime) { if (vis[v]) { - dfs(dfs, v, cost + t, value); + dfs(v, cost + t, value); } else { vis[v] = true; - dfs(dfs, v, cost + t, value + values[v]); + dfs(v, cost + t, value + values[v]); vis[v] = false; } } } }; - dfs(dfs, 0, 0, values[0]); + dfs(0, 0, values[0]); return ans; } }; diff --git a/solution/2000-2099/2065.Maximum Path Quality of a Graph/README_EN.md b/solution/2000-2099/2065.Maximum Path Quality of a Graph/README_EN.md index 7597aa91d9b95..621629af6311d 100644 --- a/solution/2000-2099/2065.Maximum Path Quality of a Graph/README_EN.md +++ b/solution/2000-2099/2065.Maximum Path Quality of a Graph/README_EN.md @@ -196,23 +196,23 @@ public: memset(vis, false, sizeof(vis)); vis[0] = true; int ans = 0; - auto dfs = [&](auto&& dfs, int u, int cost, int value) -> void { + auto dfs = [&](this auto&& dfs, int u, int cost, int value) -> void { if (u == 0) { ans = max(ans, value); } for (auto& [v, t] : g[u]) { if (cost + t <= maxTime) { if (vis[v]) { - dfs(dfs, v, cost + t, value); + dfs(v, cost + t, value); } else { vis[v] = true; - dfs(dfs, v, cost + t, value + values[v]); + dfs(v, cost + t, value + values[v]); vis[v] = false; } } } }; - dfs(dfs, 0, 0, values[0]); + dfs(0, 0, values[0]); return ans; } }; diff --git a/solution/2000-2099/2065.Maximum Path Quality of a Graph/Solution.cpp b/solution/2000-2099/2065.Maximum Path Quality of a Graph/Solution.cpp index e39e7a56db75a..83b1a7b0c214a 100644 --- a/solution/2000-2099/2065.Maximum Path Quality of a Graph/Solution.cpp +++ b/solution/2000-2099/2065.Maximum Path Quality of a Graph/Solution.cpp @@ -12,23 +12,23 @@ class Solution { memset(vis, false, sizeof(vis)); vis[0] = true; int ans = 0; - auto dfs = [&](auto&& dfs, int u, int cost, int value) -> void { + auto dfs = [&](this auto&& dfs, int u, int cost, int value) -> void { if (u == 0) { ans = max(ans, value); } for (auto& [v, t] : g[u]) { if (cost + t <= maxTime) { if (vis[v]) { - dfs(dfs, v, cost + t, value); + dfs(v, cost + t, value); } else { vis[v] = true; - dfs(dfs, v, cost + t, value + values[v]); + dfs(v, cost + t, value + values[v]); vis[v] = false; } } } }; - dfs(dfs, 0, 0, values[0]); + dfs(0, 0, values[0]); return ans; } -}; \ No newline at end of file +}; diff --git a/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README.md b/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README.md index 12675c05bd550..65bcd84fb5f08 100644 --- a/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README.md +++ b/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README.md @@ -165,7 +165,7 @@ public: int f[n][3]; memset(f, -1, sizeof(f)); const int mod = 1e9 + 7; - auto dfs = [&](auto&& dfs, int i, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int k) -> int { if (i >= n) { return k == 2; } @@ -176,13 +176,13 @@ public: if (k > 2) { return 0; } - f[i][k] = dfs(dfs, i + 1, k); + f[i][k] = dfs(i + 1, k); if (k == 2) { - f[i][k] = (f[i][k] + dfs(dfs, i + 1, 0)) % mod; + f[i][k] = (f[i][k] + dfs(i + 1, 0)) % mod; } return f[i][k]; }; - return dfs(dfs, 0, 0); + return dfs(0, 0); } }; ``` diff --git a/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README_EN.md b/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README_EN.md index cc52bf987ef3e..e30764427f6e3 100644 --- a/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README_EN.md +++ b/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/README_EN.md @@ -160,7 +160,7 @@ public: int f[n][3]; memset(f, -1, sizeof(f)); const int mod = 1e9 + 7; - auto dfs = [&](auto&& dfs, int i, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int k) -> int { if (i >= n) { return k == 2; } @@ -171,13 +171,13 @@ public: if (k > 2) { return 0; } - f[i][k] = dfs(dfs, i + 1, k); + f[i][k] = dfs(i + 1, k); if (k == 2) { - f[i][k] = (f[i][k] + dfs(dfs, i + 1, 0)) % mod; + f[i][k] = (f[i][k] + dfs(i + 1, 0)) % mod; } return f[i][k]; }; - return dfs(dfs, 0, 0); + return dfs(0, 0); } }; ``` diff --git a/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/Solution.cpp b/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/Solution.cpp index 48a19f5eade14..447467c2863dc 100644 --- a/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/Solution.cpp +++ b/solution/2100-2199/2147.Number of Ways to Divide a Long Corridor/Solution.cpp @@ -5,7 +5,7 @@ class Solution { int f[n][3]; memset(f, -1, sizeof(f)); const int mod = 1e9 + 7; - auto dfs = [&](auto&& dfs, int i, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int k) -> int { if (i >= n) { return k == 2; } @@ -16,12 +16,12 @@ class Solution { if (k > 2) { return 0; } - f[i][k] = dfs(dfs, i + 1, k); + f[i][k] = dfs(i + 1, k); if (k == 2) { - f[i][k] = (f[i][k] + dfs(dfs, i + 1, 0)) % mod; + f[i][k] = (f[i][k] + dfs(i + 1, 0)) % mod; } return f[i][k]; }; - return dfs(dfs, 0, 0); + return dfs(0, 0); } }; diff --git a/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README.md b/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README.md index 688c500c92f1c..d99e0ac6c6d85 100644 --- a/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README.md +++ b/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README.md @@ -162,12 +162,12 @@ class Solution { public: int averageOfSubtree(TreeNode* root) { int ans = 0; - auto dfs = [&](auto&& dfs, TreeNode* root) -> pair { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> pair { if (!root) { return {0, 0}; } - auto [ls, ln] = dfs(dfs, root->left); - auto [rs, rn] = dfs(dfs, root->right); + auto [ls, ln] = dfs(root->left); + auto [rs, rn] = dfs(root->right); int s = ls + rs + root->val; int n = ln + rn + 1; if (s / n == root->val) { @@ -175,7 +175,7 @@ public: } return {s, n}; }; - dfs(dfs, root); + dfs(root); return ans; } }; diff --git a/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README_EN.md b/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README_EN.md index ed387dd7185c1..f75203cb491ff 100644 --- a/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README_EN.md +++ b/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/README_EN.md @@ -35,7 +35,7 @@ tags:
 Input: root = [4,8,5,0,1,null,6]
 Output: 5
-Explanation: 
+Explanation:
 For the node with value 4: The average of its subtree is (4 + 8 + 5 + 0 + 1 + 6) / 6 = 24 / 6 = 4.
 For the node with value 5: The average of its subtree is (5 + 6) / 2 = 11 / 2 = 5.
 For the node with value 0: The average of its subtree is 0 / 1 = 0.
@@ -162,12 +162,12 @@ class Solution {
 public:
     int averageOfSubtree(TreeNode* root) {
         int ans = 0;
-        auto dfs = [&](auto&& dfs, TreeNode* root) -> pair {
+        auto dfs = [&](this auto&& dfs, TreeNode* root) -> pair {
             if (!root) {
                 return {0, 0};
             }
-            auto [ls, ln] = dfs(dfs, root->left);
-            auto [rs, rn] = dfs(dfs, root->right);
+            auto [ls, ln] = dfs(root->left);
+            auto [rs, rn] = dfs(root->right);
             int s = ls + rs + root->val;
             int n = ln + rn + 1;
             if (s / n == root->val) {
@@ -175,7 +175,7 @@ public:
             }
             return {s, n};
         };
-        dfs(dfs, root);
+        dfs(root);
         return ans;
     }
 };
diff --git a/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/Solution.cpp b/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/Solution.cpp
index 467c4e5344ab2..71f48654eb48c 100644
--- a/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/Solution.cpp	
+++ b/solution/2200-2299/2265.Count Nodes Equal to Average of Subtree/Solution.cpp	
@@ -13,12 +13,12 @@ class Solution {
 public:
     int averageOfSubtree(TreeNode* root) {
         int ans = 0;
-        auto dfs = [&](auto&& dfs, TreeNode* root) -> pair {
+        auto dfs = [&](this auto&& dfs, TreeNode* root) -> pair {
             if (!root) {
                 return {0, 0};
             }
-            auto [ls, ln] = dfs(dfs, root->left);
-            auto [rs, rn] = dfs(dfs, root->right);
+            auto [ls, ln] = dfs(root->left);
+            auto [rs, rn] = dfs(root->right);
             int s = ls + rs + root->val;
             int n = ln + rn + 1;
             if (s / n == root->val) {
@@ -26,7 +26,7 @@ class Solution {
             }
             return {s, n};
         };
-        dfs(dfs, root);
+        dfs(root);
         return ans;
     }
 };
diff --git a/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README.md b/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README.md
index 59498d4ee595e..d6d3ddc6b738f 100644
--- a/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README.md	
+++ b/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README.md	
@@ -176,7 +176,7 @@ public:
         bool vis[m][n][m + n];
         memset(vis, false, sizeof(vis));
         int dirs[3] = {1, 0, 1};
-        auto dfs = [&](auto&& dfs, int i, int j, int k) -> bool {
+        auto dfs = [&](this auto&& dfs, int i, int j, int k) -> bool {
             if (vis[i][j][k]) {
                 return false;
             }
@@ -190,13 +190,13 @@ public:
             }
             for (int d = 0; d < 2; ++d) {
                 int x = i + dirs[d], y = j + dirs[d + 1];
-                if (x >= 0 && x < m && y >= 0 && y < n && dfs(dfs, x, y, k)) {
+                if (x >= 0 && x < m && y >= 0 && y < n && dfs(x, y, k)) {
                     return true;
                 }
             }
             return false;
         };
-        return dfs(dfs, 0, 0, 0);
+        return dfs(0, 0, 0);
     }
 };
 ```
diff --git a/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README_EN.md b/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README_EN.md
index e04f10d9c0f91..a7058d7a85430 100644
--- a/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README_EN.md	
+++ b/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/README_EN.md	
@@ -170,7 +170,7 @@ public:
         bool vis[m][n][m + n];
         memset(vis, false, sizeof(vis));
         int dirs[3] = {1, 0, 1};
-        auto dfs = [&](auto&& dfs, int i, int j, int k) -> bool {
+        auto dfs = [&](this auto&& dfs, int i, int j, int k) -> bool {
             if (vis[i][j][k]) {
                 return false;
             }
@@ -184,13 +184,13 @@ public:
             }
             for (int d = 0; d < 2; ++d) {
                 int x = i + dirs[d], y = j + dirs[d + 1];
-                if (x >= 0 && x < m && y >= 0 && y < n && dfs(dfs, x, y, k)) {
+                if (x >= 0 && x < m && y >= 0 && y < n && dfs(x, y, k)) {
                     return true;
                 }
             }
             return false;
         };
-        return dfs(dfs, 0, 0, 0);
+        return dfs(0, 0, 0);
     }
 };
 ```
diff --git a/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/Solution.cpp b/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/Solution.cpp
index 100bb9ad8298a..e77e1026dcb36 100644
--- a/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/Solution.cpp	
+++ b/solution/2200-2299/2267.Check if There Is a Valid Parentheses String Path/Solution.cpp	
@@ -8,7 +8,7 @@ class Solution {
         bool vis[m][n][m + n];
         memset(vis, false, sizeof(vis));
         int dirs[3] = {1, 0, 1};
-        auto dfs = [&](auto&& dfs, int i, int j, int k) -> bool {
+        auto dfs = [&](this auto&& dfs, int i, int j, int k) -> bool {
             if (vis[i][j][k]) {
                 return false;
             }
@@ -22,12 +22,12 @@ class Solution {
             }
             for (int d = 0; d < 2; ++d) {
                 int x = i + dirs[d], y = j + dirs[d + 1];
-                if (x >= 0 && x < m && y >= 0 && y < n && dfs(dfs, x, y, k)) {
+                if (x >= 0 && x < m && y >= 0 && y < n && dfs(x, y, k)) {
                     return true;
                 }
             }
             return false;
         };
-        return dfs(dfs, 0, 0, 0);
+        return dfs(0, 0, 0);
     }
 };
diff --git a/solution/2300-2399/2376.Count Special Integers/README.md b/solution/2300-2399/2376.Count Special Integers/README.md
index 937267ea23566..ea1b1f3d1bec8 100644
--- a/solution/2300-2399/2376.Count Special Integers/README.md	
+++ b/solution/2300-2399/2376.Count Special Integers/README.md	
@@ -185,7 +185,7 @@ public:
         int m = s.size();
         int f[m][1 << 10];
         memset(f, -1, sizeof(f));
-        auto dfs = [&](auto&& dfs, int i, int mask, bool lead, bool limit) -> int {
+        auto dfs = [&](this auto&& dfs, int i, int mask, bool lead, bool limit) -> int {
             if (i >= m) {
                 return lead ^ 1;
             }
@@ -199,9 +199,9 @@ public:
                     continue;
                 }
                 if (lead && j == 0) {
-                    ans += dfs(dfs, i + 1, mask, true, limit && j == up);
+                    ans += dfs(i + 1, mask, true, limit && j == up);
                 } else {
-                    ans += dfs(dfs, i + 1, mask | (1 << j), false, limit && j == up);
+                    ans += dfs(i + 1, mask | (1 << j), false, limit && j == up);
                 }
             }
             if (!limit && !lead) {
@@ -209,7 +209,7 @@ public:
             }
             return ans;
         };
-        return dfs(dfs, 0, 0, true, true);
+        return dfs(0, 0, true, true);
     }
 };
 ```
diff --git a/solution/2300-2399/2376.Count Special Integers/README_EN.md b/solution/2300-2399/2376.Count Special Integers/README_EN.md
index 20bc66126472e..be1aab26cc632 100644
--- a/solution/2300-2399/2376.Count Special Integers/README_EN.md	
+++ b/solution/2300-2399/2376.Count Special Integers/README_EN.md	
@@ -183,7 +183,7 @@ public:
         int m = s.size();
         int f[m][1 << 10];
         memset(f, -1, sizeof(f));
-        auto dfs = [&](auto&& dfs, int i, int mask, bool lead, bool limit) -> int {
+        auto dfs = [&](this auto&& dfs, int i, int mask, bool lead, bool limit) -> int {
             if (i >= m) {
                 return lead ^ 1;
             }
@@ -197,9 +197,9 @@ public:
                     continue;
                 }
                 if (lead && j == 0) {
-                    ans += dfs(dfs, i + 1, mask, true, limit && j == up);
+                    ans += dfs(i + 1, mask, true, limit && j == up);
                 } else {
-                    ans += dfs(dfs, i + 1, mask | (1 << j), false, limit && j == up);
+                    ans += dfs(i + 1, mask | (1 << j), false, limit && j == up);
                 }
             }
             if (!limit && !lead) {
@@ -207,7 +207,7 @@ public:
             }
             return ans;
         };
-        return dfs(dfs, 0, 0, true, true);
+        return dfs(0, 0, true, true);
     }
 };
 ```
diff --git a/solution/2300-2399/2376.Count Special Integers/Solution.cpp b/solution/2300-2399/2376.Count Special Integers/Solution.cpp
index 35eaa189cc102..fd6baf558cb5c 100644
--- a/solution/2300-2399/2376.Count Special Integers/Solution.cpp	
+++ b/solution/2300-2399/2376.Count Special Integers/Solution.cpp	
@@ -5,7 +5,7 @@ class Solution {
         int m = s.size();
         int f[m][1 << 10];
         memset(f, -1, sizeof(f));
-        auto dfs = [&](auto&& dfs, int i, int mask, bool lead, bool limit) -> int {
+        auto dfs = [&](this auto&& dfs, int i, int mask, bool lead, bool limit) -> int {
             if (i >= m) {
                 return lead ^ 1;
             }
@@ -19,9 +19,9 @@ class Solution {
                     continue;
                 }
                 if (lead && j == 0) {
-                    ans += dfs(dfs, i + 1, mask, true, limit && j == up);
+                    ans += dfs(i + 1, mask, true, limit && j == up);
                 } else {
-                    ans += dfs(dfs, i + 1, mask | (1 << j), false, limit && j == up);
+                    ans += dfs(i + 1, mask | (1 << j), false, limit && j == up);
                 }
             }
             if (!limit && !lead) {
@@ -29,6 +29,6 @@ class Solution {
             }
             return ans;
         };
-        return dfs(dfs, 0, 0, true, true);
+        return dfs(0, 0, true, true);
     }
 };
diff --git a/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README.md b/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README.md
index 694502cbb95ac..e50f1b8e4aa65 100644
--- a/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README.md	
+++ b/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README.md	
@@ -134,7 +134,7 @@ public:
         const int mod = 1e9 + 7;
         int f[k + 1][k + 1];
         memset(f, -1, sizeof(f));
-        auto dfs = [&](auto&& dfs, int i, int j) -> int {
+        auto dfs = [&](this auto&& dfs, int i, int j) -> int {
             if (i > j || j < 0) {
                 return 0;
             }
@@ -144,10 +144,10 @@ public:
             if (f[i][j] != -1) {
                 return f[i][j];
             }
-            f[i][j] = (dfs(dfs, i + 1, j - 1) + dfs(dfs, abs(i - 1), j - 1)) % mod;
+            f[i][j] = (dfs(i + 1, j - 1) + dfs(abs(i - 1), j - 1)) % mod;
             return f[i][j];
         };
-        return dfs(dfs, abs(startPos - endPos), k);
+        return dfs(abs(startPos - endPos), k);
     }
 };
 ```
diff --git a/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README_EN.md b/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README_EN.md
index e149e4a11f5fd..503257d79d40b 100644
--- a/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README_EN.md	
+++ b/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/README_EN.md	
@@ -135,7 +135,7 @@ public:
         const int mod = 1e9 + 7;
         int f[k + 1][k + 1];
         memset(f, -1, sizeof(f));
-        auto dfs = [&](auto&& dfs, int i, int j) -> int {
+        auto dfs = [&](this auto&& dfs, int i, int j) -> int {
             if (i > j || j < 0) {
                 return 0;
             }
@@ -145,10 +145,10 @@ public:
             if (f[i][j] != -1) {
                 return f[i][j];
             }
-            f[i][j] = (dfs(dfs, i + 1, j - 1) + dfs(dfs, abs(i - 1), j - 1)) % mod;
+            f[i][j] = (dfs(i + 1, j - 1) + dfs(abs(i - 1), j - 1)) % mod;
             return f[i][j];
         };
-        return dfs(dfs, abs(startPos - endPos), k);
+        return dfs(abs(startPos - endPos), k);
     }
 };
 ```
diff --git a/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/Solution.cpp b/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/Solution.cpp
index ead496c17fd7e..c638a428e6c7a 100644
--- a/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/Solution.cpp	
+++ b/solution/2400-2499/2400.Number of Ways to Reach a Position After Exactly k Steps/Solution.cpp	
@@ -4,7 +4,7 @@ class Solution {
         const int mod = 1e9 + 7;
         int f[k + 1][k + 1];
         memset(f, -1, sizeof(f));
-        auto dfs = [&](auto&& dfs, int i, int j) -> int {
+        auto dfs = [&](this auto&& dfs, int i, int j) -> int {
             if (i > j || j < 0) {
                 return 0;
             }
@@ -14,9 +14,9 @@ class Solution {
             if (f[i][j] != -1) {
                 return f[i][j];
             }
-            f[i][j] = (dfs(dfs, i + 1, j - 1) + dfs(dfs, abs(i - 1), j - 1)) % mod;
+            f[i][j] = (dfs(i + 1, j - 1) + dfs(abs(i - 1), j - 1)) % mod;
             return f[i][j];
         };
-        return dfs(dfs, abs(startPos - endPos), k);
+        return dfs(abs(startPos - endPos), k);
     }
 };
diff --git a/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README.md b/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README.md
index 2af89016ca1d3..d64141390c1b6 100644
--- a/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README.md	
+++ b/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README.md	
@@ -174,7 +174,7 @@ public:
         int n = power.size();
         long long f[1 << n];
         memset(f, -1, sizeof(f));
-        auto dfs = [&](auto&& dfs, int mask) -> long long {
+        auto dfs = [&](this auto&& dfs, int mask) -> long long {
             if (mask == 0) {
                 return 0;
             }
@@ -185,12 +185,12 @@ public:
             int gain = 1 + (n - __builtin_popcount(mask));
             for (int i = 0; i < n; ++i) {
                 if (mask >> i & 1) {
-                    f[mask] = min(f[mask], dfs(dfs, mask ^ (1 << i)) + (power[i] + gain - 1) / gain);
+                    f[mask] = min(f[mask], dfs(mask ^ (1 << i)) + (power[i] + gain - 1) / gain);
                 }
             }
             return f[mask];
         };
-        return dfs(dfs, (1 << n) - 1);
+        return dfs((1 << n) - 1);
     }
 };
 ```
diff --git a/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README_EN.md b/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README_EN.md
index 5a3d87cf8ea9f..93fc6739215de 100644
--- a/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README_EN.md	
+++ b/solution/2400-2499/2403.Minimum Time to Kill All Monsters/README_EN.md	
@@ -43,7 +43,7 @@ tags:
 - Day 2: Gain 2 mana points to get a total of 2 mana points.
 - Day 3: Gain 2 mana points to get a total of 4 mana points. Spend all mana points to kill the 3rd monster.
 - Day 4: Gain 3 mana points to get a total of 3 mana points. Spend all mana points to kill the 1st monster.
-It can be proven that 4 is the minimum number of days needed. 
+It can be proven that 4 is the minimum number of days needed.
 

Example 2:

@@ -56,7 +56,7 @@ It can be proven that 4 is the minimum number of days needed. - Day 2: Gain 2 mana points to get a total of 2 mana points. Spend all mana points to kill the 2nd monster. - Day 3: Gain 3 mana points to get a total of 3 mana points. - Day 4: Gain 3 mana points to get a total of 6 mana points. Spend all mana points to kill the 3rd monster. -It can be proven that 4 is the minimum number of days needed. +It can be proven that 4 is the minimum number of days needed.

Example 3:

@@ -168,7 +168,7 @@ public: int n = power.size(); long long f[1 << n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int mask) -> long long { + auto dfs = [&](this auto&& dfs, int mask) -> long long { if (mask == 0) { return 0; } @@ -179,12 +179,12 @@ public: int gain = 1 + (n - __builtin_popcount(mask)); for (int i = 0; i < n; ++i) { if (mask >> i & 1) { - f[mask] = min(f[mask], dfs(dfs, mask ^ (1 << i)) + (power[i] + gain - 1) / gain); + f[mask] = min(f[mask], dfs(mask ^ (1 << i)) + (power[i] + gain - 1) / gain); } } return f[mask]; }; - return dfs(dfs, (1 << n) - 1); + return dfs((1 << n) - 1); } }; ``` diff --git a/solution/2400-2499/2403.Minimum Time to Kill All Monsters/Solution.cpp b/solution/2400-2499/2403.Minimum Time to Kill All Monsters/Solution.cpp index 269f270fa1f4a..6873eb2115ddd 100644 --- a/solution/2400-2499/2403.Minimum Time to Kill All Monsters/Solution.cpp +++ b/solution/2400-2499/2403.Minimum Time to Kill All Monsters/Solution.cpp @@ -4,7 +4,7 @@ class Solution { int n = power.size(); long long f[1 << n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int mask) -> long long { + auto dfs = [&](this auto&& dfs, int mask) -> long long { if (mask == 0) { return 0; } @@ -15,11 +15,11 @@ class Solution { int gain = 1 + (n - __builtin_popcount(mask)); for (int i = 0; i < n; ++i) { if (mask >> i & 1) { - f[mask] = min(f[mask], dfs(dfs, mask ^ (1 << i)) + (power[i] + gain - 1) / gain); + f[mask] = min(f[mask], dfs(mask ^ (1 << i)) + (power[i] + gain - 1) / gain); } } return f[mask]; }; - return dfs(dfs, (1 << n) - 1); + return dfs((1 << n) - 1); } }; diff --git a/solution/2500-2599/2545.Sort the Students by Their Kth Score/README.md b/solution/2500-2599/2545.Sort the Students by Their Kth Score/README.md index 12f1854d530c0..bb61f2bf285d9 100644 --- a/solution/2500-2599/2545.Sort the Students by Their Kth Score/README.md +++ b/solution/2500-2599/2545.Sort the Students by Their Kth Score/README.md @@ -74,9 +74,9 @@ tags: ### 方法一:排序 -我们将 `score` 按照第 $k$ 列的分数从大到小排序,然后返回即可。 +我们直接将 $\textit{score}$ 按照第 $k$ 列的分数从大到小排序,然后返回即可。 -时间复杂度 $O(m \times \log m)$,空间复杂度 $O(1)$。其中 $m$ 为 `score` 的行数。 +时间复杂度 $O(m \times \log m)$,空间复杂度 $O(\log m)$。其中 $m$ 为 $\textit{score}$ 的行数。 @@ -105,7 +105,7 @@ class Solution { class Solution { public: vector> sortTheStudents(vector>& score, int k) { - sort(score.begin(), score.end(), [&](const auto& a, const auto& b) { return a[k] > b[k]; }); + ranges::sort(score, [k](const auto& a, const auto& b) { return a[k] > b[k]; }); return score; } }; diff --git a/solution/2500-2599/2545.Sort the Students by Their Kth Score/README_EN.md b/solution/2500-2599/2545.Sort the Students by Their Kth Score/README_EN.md index d484ec0bffcb9..c157a391fc043 100644 --- a/solution/2500-2599/2545.Sort the Students by Their Kth Score/README_EN.md +++ b/solution/2500-2599/2545.Sort the Students by Their Kth Score/README_EN.md @@ -68,9 +68,9 @@ tags: ### Solution 1: Sorting -We sort score in descending order based on the scores in the $k^{th}$ column, and then return it. +We directly sort $\textit{score}$ in descending order based on the scores in the $k$-th column, and then return the result. -The time complexity is $O(m \times \log m)$, and the space complexity is $O(1)$. Here, $m$ is the number of rows in score. +The time complexity is $O(m \times \log m)$, and the space complexity is $O(\log m)$. Here, $m$ is the number of rows in $\textit{score}$. @@ -99,7 +99,7 @@ class Solution { class Solution { public: vector> sortTheStudents(vector>& score, int k) { - sort(score.begin(), score.end(), [&](const auto& a, const auto& b) { return a[k] > b[k]; }); + ranges::sort(score, [k](const auto& a, const auto& b) { return a[k] > b[k]; }); return score; } }; diff --git a/solution/2500-2599/2545.Sort the Students by Their Kth Score/Solution.cpp b/solution/2500-2599/2545.Sort the Students by Their Kth Score/Solution.cpp index d1b77497d983f..397eb19aeeedf 100644 --- a/solution/2500-2599/2545.Sort the Students by Their Kth Score/Solution.cpp +++ b/solution/2500-2599/2545.Sort the Students by Their Kth Score/Solution.cpp @@ -1,7 +1,7 @@ class Solution { public: vector> sortTheStudents(vector>& score, int k) { - sort(score.begin(), score.end(), [&](const auto& a, const auto& b) { return a[k] > b[k]; }); + ranges::sort(score, [k](const auto& a, const auto& b) { return a[k] > b[k]; }); return score; } -}; \ No newline at end of file +}; diff --git a/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README.md b/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README.md index 7b1fa3d3b7bae..1d73738c1d099 100644 --- a/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README.md +++ b/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README.md @@ -144,18 +144,18 @@ public: int n = num.size(); int f[n][25]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int k) -> int { if (i == n) { return k == 0 ? 0 : n; } if (f[i][k] != -1) { return f[i][k]; } - f[i][k] = dfs(dfs, i + 1, k) + 1; - f[i][k] = min(f[i][k], dfs(dfs, i + 1, (k * 10 + num[i] - '0') % 25)); + f[i][k] = dfs(i + 1, k) + 1; + f[i][k] = min(f[i][k], dfs(i + 1, (k * 10 + num[i] - '0') % 25)); return f[i][k]; }; - return dfs(dfs, 0, 0); + return dfs(0, 0); } }; ``` diff --git a/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README_EN.md b/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README_EN.md index 6308ad3d9db7c..53e66762f3b4a 100644 --- a/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README_EN.md +++ b/solution/2800-2899/2844.Minimum Operations to Make a Special Number/README_EN.md @@ -141,18 +141,18 @@ public: int n = num.size(); int f[n][25]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int k) -> int { if (i == n) { return k == 0 ? 0 : n; } if (f[i][k] != -1) { return f[i][k]; } - f[i][k] = dfs(dfs, i + 1, k) + 1; - f[i][k] = min(f[i][k], dfs(dfs, i + 1, (k * 10 + num[i] - '0') % 25)); + f[i][k] = dfs(i + 1, k) + 1; + f[i][k] = min(f[i][k], dfs(i + 1, (k * 10 + num[i] - '0') % 25)); return f[i][k]; }; - return dfs(dfs, 0, 0); + return dfs(0, 0); } }; ``` diff --git a/solution/2800-2899/2844.Minimum Operations to Make a Special Number/Solution.cpp b/solution/2800-2899/2844.Minimum Operations to Make a Special Number/Solution.cpp index e8a8ee38b3f0a..f9ab5d6a76afd 100644 --- a/solution/2800-2899/2844.Minimum Operations to Make a Special Number/Solution.cpp +++ b/solution/2800-2899/2844.Minimum Operations to Make a Special Number/Solution.cpp @@ -4,17 +4,17 @@ class Solution { int n = num.size(); int f[n][25]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int k) -> int { if (i == n) { return k == 0 ? 0 : n; } if (f[i][k] != -1) { return f[i][k]; } - f[i][k] = dfs(dfs, i + 1, k) + 1; - f[i][k] = min(f[i][k], dfs(dfs, i + 1, (k * 10 + num[i] - '0') % 25)); + f[i][k] = dfs(i + 1, k) + 1; + f[i][k] = min(f[i][k], dfs(i + 1, (k * 10 + num[i] - '0') % 25)); return f[i][k]; }; - return dfs(dfs, 0, 0); + return dfs(0, 0); } -}; \ No newline at end of file +}; diff --git a/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README.md b/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README.md index b174ef493049b..e0ab4f426e90c 100644 --- a/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README.md +++ b/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README.md @@ -342,7 +342,7 @@ public: ll l = 1, r = 1e17; ll num = 0; ll f[65][65]; - auto dfs = [&](auto&& dfs, int pos, int cnt, bool limit) -> ll { + auto dfs = [&](this auto&& dfs, int pos, int cnt, bool limit) -> ll { if (pos == 0) { return cnt; } @@ -352,7 +352,7 @@ public: int up = limit ? num >> (pos - 1) & 1 : 1; ll ans = 0; for (int i = 0; i <= up; ++i) { - ans += dfs(dfs, pos - 1, cnt + (i == 1 && pos % x == 0), limit && i == up); + ans += dfs(pos - 1, cnt + (i == 1 && pos % x == 0), limit && i == up); } if (!limit) { f[pos][cnt] = ans; @@ -364,7 +364,7 @@ public: num = mid; memset(f, -1, sizeof(f)); int pos = 64 - __builtin_clzll(mid); - if (dfs(dfs, pos, 0, true) <= k) { + if (dfs(pos, 0, true) <= k) { l = mid; } else { r = mid - 1; diff --git a/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README_EN.md b/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README_EN.md index 0671febffa623..f7239a8cdebc6 100644 --- a/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README_EN.md +++ b/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/README_EN.md @@ -346,7 +346,7 @@ public: ll l = 1, r = 1e17; ll num = 0; ll f[65][65]; - auto dfs = [&](auto&& dfs, int pos, int cnt, bool limit) -> ll { + auto dfs = [&](this auto&& dfs, int pos, int cnt, bool limit) -> ll { if (pos == 0) { return cnt; } @@ -356,7 +356,7 @@ public: int up = limit ? num >> (pos - 1) & 1 : 1; ll ans = 0; for (int i = 0; i <= up; ++i) { - ans += dfs(dfs, pos - 1, cnt + (i == 1 && pos % x == 0), limit && i == up); + ans += dfs(pos - 1, cnt + (i == 1 && pos % x == 0), limit && i == up); } if (!limit) { f[pos][cnt] = ans; @@ -368,7 +368,7 @@ public: num = mid; memset(f, -1, sizeof(f)); int pos = 64 - __builtin_clzll(mid); - if (dfs(dfs, pos, 0, true) <= k) { + if (dfs(pos, 0, true) <= k) { l = mid; } else { r = mid - 1; diff --git a/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/Solution.cpp b/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/Solution.cpp index c2417f4135812..cc4aa2642aefc 100644 --- a/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/Solution.cpp +++ b/solution/3000-3099/3007.Maximum Number That Sum of the Prices Is Less Than or Equal to K/Solution.cpp @@ -5,7 +5,7 @@ class Solution { ll l = 1, r = 1e17; ll num = 0; ll f[65][65]; - auto dfs = [&](auto&& dfs, int pos, int cnt, bool limit) -> ll { + auto dfs = [&](this auto&& dfs, int pos, int cnt, bool limit) -> ll { if (pos == 0) { return cnt; } @@ -15,7 +15,7 @@ class Solution { int up = limit ? num >> (pos - 1) & 1 : 1; ll ans = 0; for (int i = 0; i <= up; ++i) { - ans += dfs(dfs, pos - 1, cnt + (i == 1 && pos % x == 0), limit && i == up); + ans += dfs(pos - 1, cnt + (i == 1 && pos % x == 0), limit && i == up); } if (!limit) { f[pos][cnt] = ans; @@ -27,7 +27,7 @@ class Solution { num = mid; memset(f, -1, sizeof(f)); int pos = 64 - __builtin_clzll(mid); - if (dfs(dfs, pos, 0, true) <= k) { + if (dfs(pos, 0, true) <= k) { l = mid; } else { r = mid - 1; diff --git a/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README.md b/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README.md index 3ca9f25bb9fd5..a807d32a27bd7 100644 --- a/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README.md +++ b/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README.md @@ -175,7 +175,7 @@ public: const int mod = 1e9 + 7; int n = nums.size(); sort(nums.begin(), nums.end()); - auto dfs = [&](auto&& dfs, int i, int j, int k, int mi) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int k, int mi) -> int { if (i >= n) { return k == 0 ? mi : 0; } @@ -186,17 +186,17 @@ public: if (f.contains(key)) { return f[key]; } - long long ans = dfs(dfs, i + 1, j, k, mi); + long long ans = dfs(i + 1, j, k, mi); if (j == n) { - ans += dfs(dfs, i + 1, i, k - 1, mi); + ans += dfs(i + 1, i, k - 1, mi); } else { - ans += dfs(dfs, i + 1, i, k - 1, min(mi, nums[i] - nums[j])); + ans += dfs(i + 1, i, k - 1, min(mi, nums[i] - nums[j])); } ans %= mod; f[key] = ans; return f[key]; }; - return dfs(dfs, 0, n, k, INT_MAX); + return dfs(0, n, k, INT_MAX); } }; ``` diff --git a/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README_EN.md b/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README_EN.md index db46b8a10d376..d481bda476fae 100644 --- a/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README_EN.md +++ b/solution/3000-3099/3098.Find the Sum of Subsequence Powers/README_EN.md @@ -173,7 +173,7 @@ public: const int mod = 1e9 + 7; int n = nums.size(); sort(nums.begin(), nums.end()); - auto dfs = [&](auto&& dfs, int i, int j, int k, int mi) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int k, int mi) -> int { if (i >= n) { return k == 0 ? mi : 0; } @@ -184,17 +184,17 @@ public: if (f.contains(key)) { return f[key]; } - long long ans = dfs(dfs, i + 1, j, k, mi); + long long ans = dfs(i + 1, j, k, mi); if (j == n) { - ans += dfs(dfs, i + 1, i, k - 1, mi); + ans += dfs(i + 1, i, k - 1, mi); } else { - ans += dfs(dfs, i + 1, i, k - 1, min(mi, nums[i] - nums[j])); + ans += dfs(i + 1, i, k - 1, min(mi, nums[i] - nums[j])); } ans %= mod; f[key] = ans; return f[key]; }; - return dfs(dfs, 0, n, k, INT_MAX); + return dfs(0, n, k, INT_MAX); } }; ``` diff --git a/solution/3000-3099/3098.Find the Sum of Subsequence Powers/Solution.cpp b/solution/3000-3099/3098.Find the Sum of Subsequence Powers/Solution.cpp index 7e5407b6435b3..8927626509f28 100644 --- a/solution/3000-3099/3098.Find the Sum of Subsequence Powers/Solution.cpp +++ b/solution/3000-3099/3098.Find the Sum of Subsequence Powers/Solution.cpp @@ -5,7 +5,7 @@ class Solution { const int mod = 1e9 + 7; int n = nums.size(); sort(nums.begin(), nums.end()); - auto dfs = [&](auto&& dfs, int i, int j, int k, int mi) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int k, int mi) -> int { if (i >= n) { return k == 0 ? mi : 0; } @@ -16,16 +16,16 @@ class Solution { if (f.contains(key)) { return f[key]; } - long long ans = dfs(dfs, i + 1, j, k, mi); + long long ans = dfs(i + 1, j, k, mi); if (j == n) { - ans += dfs(dfs, i + 1, i, k - 1, mi); + ans += dfs(i + 1, i, k - 1, mi); } else { - ans += dfs(dfs, i + 1, i, k - 1, min(mi, nums[i] - nums[j])); + ans += dfs(i + 1, i, k - 1, min(mi, nums[i] - nums[j])); } ans %= mod; f[key] = ans; return f[key]; }; - return dfs(dfs, 0, n, k, INT_MAX); + return dfs(0, n, k, INT_MAX); } -}; \ No newline at end of file +}; diff --git a/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README.md b/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README.md index c2b006949e5d9..4386225fed57a 100644 --- a/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README.md +++ b/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README.md @@ -182,7 +182,7 @@ public: const int mod = 1e9 + 7; using ll = long long; vector>> f = vector>>(zero + 1, vector>(one + 1, {-1, -1})); - auto dfs = [&](auto&& dfs, int i, int j, int k) -> ll { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> ll { if (i < 0 || j < 0) { return 0; } @@ -197,13 +197,13 @@ public: return res; } if (k == 0) { - res = (dfs(dfs, i - 1, j, 0) + dfs(dfs, i - 1, j, 1) - dfs(dfs, i - limit - 1, j, 1) + mod) % mod; + res = (dfs(i - 1, j, 0) + dfs(i - 1, j, 1) - dfs(i - limit - 1, j, 1) + mod) % mod; } else { - res = (dfs(dfs, i, j - 1, 0) + dfs(dfs, i, j - 1, 1) - dfs(dfs, i, j - limit - 1, 0) + mod) % mod; + res = (dfs(i, j - 1, 0) + dfs(i, j - 1, 1) - dfs(i, j - limit - 1, 0) + mod) % mod; } return res; }; - return (dfs(dfs, zero, one, 0) + dfs(dfs, zero, one, 1)) % mod; + return (dfs(zero, one, 0) + dfs(zero, one, 1)) % mod; } }; ``` diff --git a/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README_EN.md b/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README_EN.md index 4888d0a98822b..77fbe6bcf2753 100644 --- a/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README_EN.md +++ b/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/README_EN.md @@ -173,7 +173,7 @@ public: const int mod = 1e9 + 7; using ll = long long; vector>> f = vector>>(zero + 1, vector>(one + 1, {-1, -1})); - auto dfs = [&](auto&& dfs, int i, int j, int k) -> ll { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> ll { if (i < 0 || j < 0) { return 0; } @@ -188,13 +188,13 @@ public: return res; } if (k == 0) { - res = (dfs(dfs, i - 1, j, 0) + dfs(dfs, i - 1, j, 1) - dfs(dfs, i - limit - 1, j, 1) + mod) % mod; + res = (dfs(i - 1, j, 0) + dfs(i - 1, j, 1) - dfs(i - limit - 1, j, 1) + mod) % mod; } else { - res = (dfs(dfs, i, j - 1, 0) + dfs(dfs, i, j - 1, 1) - dfs(dfs, i, j - limit - 1, 0) + mod) % mod; + res = (dfs(i, j - 1, 0) + dfs(i, j - 1, 1) - dfs(i, j - limit - 1, 0) + mod) % mod; } return res; }; - return (dfs(dfs, zero, one, 0) + dfs(dfs, zero, one, 1)) % mod; + return (dfs(zero, one, 0) + dfs(zero, one, 1)) % mod; } }; ``` diff --git a/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/Solution.cpp b/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/Solution.cpp index dfee6678a0b5e..1d228bf7e9f07 100644 --- a/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/Solution.cpp +++ b/solution/3100-3199/3129.Find All Possible Stable Binary Arrays I/Solution.cpp @@ -4,7 +4,7 @@ class Solution { const int mod = 1e9 + 7; using ll = long long; vector>> f = vector>>(zero + 1, vector>(one + 1, {-1, -1})); - auto dfs = [&](auto&& dfs, int i, int j, int k) -> ll { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> ll { if (i < 0 || j < 0) { return 0; } @@ -19,12 +19,12 @@ class Solution { return res; } if (k == 0) { - res = (dfs(dfs, i - 1, j, 0) + dfs(dfs, i - 1, j, 1) - dfs(dfs, i - limit - 1, j, 1) + mod) % mod; + res = (dfs(i - 1, j, 0) + dfs(i - 1, j, 1) - dfs(i - limit - 1, j, 1) + mod) % mod; } else { - res = (dfs(dfs, i, j - 1, 0) + dfs(dfs, i, j - 1, 1) - dfs(dfs, i, j - limit - 1, 0) + mod) % mod; + res = (dfs(i, j - 1, 0) + dfs(i, j - 1, 1) - dfs(i, j - limit - 1, 0) + mod) % mod; } return res; }; - return (dfs(dfs, zero, one, 0) + dfs(dfs, zero, one, 1)) % mod; + return (dfs(zero, one, 0) + dfs(zero, one, 1)) % mod; } }; diff --git a/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README.md b/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README.md index 7ec6dcc5a6758..252f7dc1bf9a4 100644 --- a/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README.md +++ b/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README.md @@ -182,7 +182,7 @@ public: const int mod = 1e9 + 7; using ll = long long; vector>> f = vector>>(zero + 1, vector>(one + 1, {-1, -1})); - auto dfs = [&](auto&& dfs, int i, int j, int k) -> ll { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> ll { if (i < 0 || j < 0) { return 0; } @@ -197,13 +197,13 @@ public: return res; } if (k == 0) { - res = (dfs(dfs, i - 1, j, 0) + dfs(dfs, i - 1, j, 1) - dfs(dfs, i - limit - 1, j, 1) + mod) % mod; + res = (dfs(i - 1, j, 0) + dfs(i - 1, j, 1) - dfs(i - limit - 1, j, 1) + mod) % mod; } else { - res = (dfs(dfs, i, j - 1, 0) + dfs(dfs, i, j - 1, 1) - dfs(dfs, i, j - limit - 1, 0) + mod) % mod; + res = (dfs(i, j - 1, 0) + dfs(i, j - 1, 1) - dfs(i, j - limit - 1, 0) + mod) % mod; } return res; }; - return (dfs(dfs, zero, one, 0) + dfs(dfs, zero, one, 1)) % mod; + return (dfs(zero, one, 0) + dfs(zero, one, 1)) % mod; } }; ``` diff --git a/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README_EN.md b/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README_EN.md index db7a668d7cdcc..e3d57b0996d23 100644 --- a/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README_EN.md +++ b/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/README_EN.md @@ -173,7 +173,7 @@ public: const int mod = 1e9 + 7; using ll = long long; vector>> f = vector>>(zero + 1, vector>(one + 1, {-1, -1})); - auto dfs = [&](auto&& dfs, int i, int j, int k) -> ll { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> ll { if (i < 0 || j < 0) { return 0; } @@ -188,13 +188,13 @@ public: return res; } if (k == 0) { - res = (dfs(dfs, i - 1, j, 0) + dfs(dfs, i - 1, j, 1) - dfs(dfs, i - limit - 1, j, 1) + mod) % mod; + res = (dfs(i - 1, j, 0) + dfs(i - 1, j, 1) - dfs(i - limit - 1, j, 1) + mod) % mod; } else { - res = (dfs(dfs, i, j - 1, 0) + dfs(dfs, i, j - 1, 1) - dfs(dfs, i, j - limit - 1, 0) + mod) % mod; + res = (dfs(i, j - 1, 0) + dfs(i, j - 1, 1) - dfs(i, j - limit - 1, 0) + mod) % mod; } return res; }; - return (dfs(dfs, zero, one, 0) + dfs(dfs, zero, one, 1)) % mod; + return (dfs(zero, one, 0) + dfs(zero, one, 1)) % mod; } }; ``` diff --git a/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/Solution.cpp b/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/Solution.cpp index dfee6678a0b5e..1d228bf7e9f07 100644 --- a/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/Solution.cpp +++ b/solution/3100-3199/3130.Find All Possible Stable Binary Arrays II/Solution.cpp @@ -4,7 +4,7 @@ class Solution { const int mod = 1e9 + 7; using ll = long long; vector>> f = vector>>(zero + 1, vector>(one + 1, {-1, -1})); - auto dfs = [&](auto&& dfs, int i, int j, int k) -> ll { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> ll { if (i < 0 || j < 0) { return 0; } @@ -19,12 +19,12 @@ class Solution { return res; } if (k == 0) { - res = (dfs(dfs, i - 1, j, 0) + dfs(dfs, i - 1, j, 1) - dfs(dfs, i - limit - 1, j, 1) + mod) % mod; + res = (dfs(i - 1, j, 0) + dfs(i - 1, j, 1) - dfs(i - limit - 1, j, 1) + mod) % mod; } else { - res = (dfs(dfs, i, j - 1, 0) + dfs(dfs, i, j - 1, 1) - dfs(dfs, i, j - limit - 1, 0) + mod) % mod; + res = (dfs(i, j - 1, 0) + dfs(i, j - 1, 1) - dfs(i, j - limit - 1, 0) + mod) % mod; } return res; }; - return (dfs(dfs, zero, one, 0) + dfs(dfs, zero, one, 1)) % mod; + return (dfs(zero, one, 0) + dfs(zero, one, 1)) % mod; } }; diff --git a/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README.md b/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README.md index afce030b63e1d..f045d9c3c2284 100644 --- a/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README.md +++ b/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README.md @@ -165,7 +165,7 @@ public: int n = s.size(); int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } @@ -186,12 +186,12 @@ public: ++cnt[k]; ++freq[cnt[k]]; if (freq.size() == 1) { - f[i] = min(f[i], 1 + dfs(dfs, j + 1)); + f[i] = min(f[i], 1 + dfs(j + 1)); } } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; ``` @@ -357,7 +357,7 @@ public: int n = s.size(); int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } @@ -371,12 +371,12 @@ public: k += ++cnt[s[j] - 'a'] == 1 ? 1 : 0; m = max(m, cnt[s[j] - 'a']); if (j - i + 1 == k * m) { - f[i] = min(f[i], 1 + dfs(dfs, j + 1)); + f[i] = min(f[i], 1 + dfs(j + 1)); } } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; ``` diff --git a/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README_EN.md b/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README_EN.md index 0a1cae6cedec6..633450598d0d8 100644 --- a/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README_EN.md +++ b/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/README_EN.md @@ -163,7 +163,7 @@ public: int n = s.size(); int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } @@ -184,12 +184,12 @@ public: ++cnt[k]; ++freq[cnt[k]]; if (freq.size() == 1) { - f[i] = min(f[i], 1 + dfs(dfs, j + 1)); + f[i] = min(f[i], 1 + dfs(j + 1)); } } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; ``` @@ -355,7 +355,7 @@ public: int n = s.size(); int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } @@ -369,12 +369,12 @@ public: k += ++cnt[s[j] - 'a'] == 1 ? 1 : 0; m = max(m, cnt[s[j] - 'a']); if (j - i + 1 == k * m) { - f[i] = min(f[i], 1 + dfs(dfs, j + 1)); + f[i] = min(f[i], 1 + dfs(j + 1)); } } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; ``` diff --git a/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/Solution.cpp b/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/Solution.cpp index 6bdac4b97dc72..5e169eba82627 100644 --- a/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/Solution.cpp +++ b/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/Solution.cpp @@ -4,7 +4,7 @@ class Solution { int n = s.size(); int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } @@ -25,11 +25,11 @@ class Solution { ++cnt[k]; ++freq[cnt[k]]; if (freq.size() == 1) { - f[i] = min(f[i], 1 + dfs(dfs, j + 1)); + f[i] = min(f[i], 1 + dfs(j + 1)); } } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; diff --git a/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/Solution2.cpp b/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/Solution2.cpp index 202c1223c9474..aa065b25f7d8d 100644 --- a/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/Solution2.cpp +++ b/solution/3100-3199/3144.Minimum Substring Partition of Equal Character Frequency/Solution2.cpp @@ -4,7 +4,7 @@ class Solution { int n = s.size(); int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } @@ -18,11 +18,11 @@ class Solution { k += ++cnt[s[j] - 'a'] == 1 ? 1 : 0; m = max(m, cnt[s[j] - 'a']); if (j - i + 1 == k * m) { - f[i] = min(f[i], 1 + dfs(dfs, j + 1)); + f[i] = min(f[i], 1 + dfs(j + 1)); } } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; diff --git a/solution/3100-3199/3154.Find Number of Ways to Reach the K-th Stair/README.md b/solution/3100-3199/3154.Find Number of Ways to Reach the K-th Stair/README.md index 702b20e09c08a..0c5361ef2b369 100644 --- a/solution/3100-3199/3154.Find Number of Ways to Reach the K-th Stair/README.md +++ b/solution/3100-3199/3154.Find Number of Ways to Reach the K-th Stair/README.md @@ -188,7 +188,7 @@ class Solution { public: int waysToReachStair(int k) { unordered_map f; - auto dfs = [&](auto&& dfs, int i, int j, int jump) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int jump) -> int { if (i > k + 1) { return 0; } @@ -198,13 +198,13 @@ public: } int ans = i == k ? 1 : 0; if (i > 0 && j == 0) { - ans += dfs(dfs, i - 1, 1, jump); + ans += dfs(i - 1, 1, jump); } - ans += dfs(dfs, i + (1 << jump), 0, jump + 1); + ans += dfs(i + (1 << jump), 0, jump + 1); f[key] = ans; return ans; }; - return dfs(dfs, 1, 0, 0); + return dfs(1, 0, 0); } }; ``` diff --git a/solution/3100-3199/3154.Find Number of Ways to Reach the K-th Stair/README_EN.md b/solution/3100-3199/3154.Find Number of Ways to Reach the K-th Stair/README_EN.md index 2f1f308b81842..dfdd8aa50f12d 100644 --- a/solution/3100-3199/3154.Find Number of Ways to Reach the K-th Stair/README_EN.md +++ b/solution/3100-3199/3154.Find Number of Ways to Reach the K-th Stair/README_EN.md @@ -186,7 +186,7 @@ class Solution { public: int waysToReachStair(int k) { unordered_map f; - auto dfs = [&](auto&& dfs, int i, int j, int jump) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int jump) -> int { if (i > k + 1) { return 0; } @@ -196,13 +196,13 @@ public: } int ans = i == k ? 1 : 0; if (i > 0 && j == 0) { - ans += dfs(dfs, i - 1, 1, jump); + ans += dfs(i - 1, 1, jump); } - ans += dfs(dfs, i + (1 << jump), 0, jump + 1); + ans += dfs(i + (1 << jump), 0, jump + 1); f[key] = ans; return ans; }; - return dfs(dfs, 1, 0, 0); + return dfs(1, 0, 0); } }; ``` diff --git a/solution/3100-3199/3154.Find Number of Ways to Reach the K-th Stair/Solution.cpp b/solution/3100-3199/3154.Find Number of Ways to Reach the K-th Stair/Solution.cpp index 484ee9cb8677f..3e0fd771f617c 100644 --- a/solution/3100-3199/3154.Find Number of Ways to Reach the K-th Stair/Solution.cpp +++ b/solution/3100-3199/3154.Find Number of Ways to Reach the K-th Stair/Solution.cpp @@ -2,7 +2,7 @@ class Solution { public: int waysToReachStair(int k) { unordered_map f; - auto dfs = [&](auto&& dfs, int i, int j, int jump) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int jump) -> int { if (i > k + 1) { return 0; } @@ -12,12 +12,12 @@ class Solution { } int ans = i == k ? 1 : 0; if (i > 0 && j == 0) { - ans += dfs(dfs, i - 1, 1, jump); + ans += dfs(i - 1, 1, jump); } - ans += dfs(dfs, i + (1 << jump), 0, jump + 1); + ans += dfs(i + (1 << jump), 0, jump + 1); f[key] = ans; return ans; }; - return dfs(dfs, 1, 0, 0); + return dfs(1, 0, 0); } }; diff --git a/solution/3100-3199/3196.Maximize Total Cost of Alternating Subarrays/README.md b/solution/3100-3199/3196.Maximize Total Cost of Alternating Subarrays/README.md index 3670c65248a33..881530b183b0e 100644 --- a/solution/3100-3199/3196.Maximize Total Cost of Alternating Subarrays/README.md +++ b/solution/3100-3199/3196.Maximize Total Cost of Alternating Subarrays/README.md @@ -174,20 +174,20 @@ public: int n = nums.size(); long long f[n][2]; fill(f[0], f[n], LLONG_MIN); - auto dfs = [&](auto&& dfs, int i, int j) -> long long { + auto dfs = [&](this auto&& dfs, int i, int j) -> long long { if (i >= n) { return 0; } if (f[i][j] != LLONG_MIN) { return f[i][j]; } - f[i][j] = nums[i] + dfs(dfs, i + 1, 1); + f[i][j] = nums[i] + dfs(i + 1, 1); if (j) { - f[i][j] = max(f[i][j], -nums[i] + dfs(dfs, i + 1, 0)); + f[i][j] = max(f[i][j], -nums[i] + dfs(i + 1, 0)); } return f[i][j]; }; - return dfs(dfs, 0, 0); + return dfs(0, 0); } }; ``` diff --git a/solution/3100-3199/3196.Maximize Total Cost of Alternating Subarrays/README_EN.md b/solution/3100-3199/3196.Maximize Total Cost of Alternating Subarrays/README_EN.md index 17ac12706d72f..6cf2e06864b21 100644 --- a/solution/3100-3199/3196.Maximize Total Cost of Alternating Subarrays/README_EN.md +++ b/solution/3100-3199/3196.Maximize Total Cost of Alternating Subarrays/README_EN.md @@ -172,20 +172,20 @@ public: int n = nums.size(); long long f[n][2]; fill(f[0], f[n], LLONG_MIN); - auto dfs = [&](auto&& dfs, int i, int j) -> long long { + auto dfs = [&](this auto&& dfs, int i, int j) -> long long { if (i >= n) { return 0; } if (f[i][j] != LLONG_MIN) { return f[i][j]; } - f[i][j] = nums[i] + dfs(dfs, i + 1, 1); + f[i][j] = nums[i] + dfs(i + 1, 1); if (j) { - f[i][j] = max(f[i][j], -nums[i] + dfs(dfs, i + 1, 0)); + f[i][j] = max(f[i][j], -nums[i] + dfs(i + 1, 0)); } return f[i][j]; }; - return dfs(dfs, 0, 0); + return dfs(0, 0); } }; ``` diff --git a/solution/3100-3199/3196.Maximize Total Cost of Alternating Subarrays/Solution.cpp b/solution/3100-3199/3196.Maximize Total Cost of Alternating Subarrays/Solution.cpp index a6fc85ed01db6..c30826a6237af 100644 --- a/solution/3100-3199/3196.Maximize Total Cost of Alternating Subarrays/Solution.cpp +++ b/solution/3100-3199/3196.Maximize Total Cost of Alternating Subarrays/Solution.cpp @@ -4,19 +4,19 @@ class Solution { int n = nums.size(); long long f[n][2]; fill(f[0], f[n], LLONG_MIN); - auto dfs = [&](auto&& dfs, int i, int j) -> long long { + auto dfs = [&](this auto&& dfs, int i, int j) -> long long { if (i >= n) { return 0; } if (f[i][j] != LLONG_MIN) { return f[i][j]; } - f[i][j] = nums[i] + dfs(dfs, i + 1, 1); + f[i][j] = nums[i] + dfs(i + 1, 1); if (j) { - f[i][j] = max(f[i][j], -nums[i] + dfs(dfs, i + 1, 0)); + f[i][j] = max(f[i][j], -nums[i] + dfs(i + 1, 0)); } return f[i][j]; }; - return dfs(dfs, 0, 0); + return dfs(0, 0); } -}; \ No newline at end of file +}; diff --git a/solution/3200-3299/3203.Find Minimum Diameter After Merging Two Trees/README.md b/solution/3200-3299/3203.Find Minimum Diameter After Merging Two Trees/README.md index 39c06608c846d..58092b08bfd82 100644 --- a/solution/3200-3299/3203.Find Minimum Diameter After Merging Two Trees/README.md +++ b/solution/3200-3299/3203.Find Minimum Diameter After Merging Two Trees/README.md @@ -187,10 +187,10 @@ public: g[b].push_back(a); } int ans = 0, a = 0; - auto dfs = [&](auto&& dfs, int i, int fa, int t) -> void { + auto dfs = [&](this auto&& dfs, int i, int fa, int t) -> void { for (int j : g[i]) { if (j != fa) { - dfs(dfs, j, i, t + 1); + dfs(j, i, t + 1); } } if (ans < t) { @@ -198,8 +198,8 @@ public: a = i; } }; - dfs(dfs, 0, -1, 0); - dfs(dfs, a, -1, 0); + dfs(0, -1, 0); + dfs(a, -1, 0); return ans; } }; diff --git a/solution/3200-3299/3203.Find Minimum Diameter After Merging Two Trees/README_EN.md b/solution/3200-3299/3203.Find Minimum Diameter After Merging Two Trees/README_EN.md index 8664c3b7cd422..ef28a10e96a3f 100644 --- a/solution/3200-3299/3203.Find Minimum Diameter After Merging Two Trees/README_EN.md +++ b/solution/3200-3299/3203.Find Minimum Diameter After Merging Two Trees/README_EN.md @@ -185,10 +185,10 @@ public: g[b].push_back(a); } int ans = 0, a = 0; - auto dfs = [&](auto&& dfs, int i, int fa, int t) -> void { + auto dfs = [&](this auto&& dfs, int i, int fa, int t) -> void { for (int j : g[i]) { if (j != fa) { - dfs(dfs, j, i, t + 1); + dfs(j, i, t + 1); } } if (ans < t) { @@ -196,8 +196,8 @@ public: a = i; } }; - dfs(dfs, 0, -1, 0); - dfs(dfs, a, -1, 0); + dfs(0, -1, 0); + dfs(a, -1, 0); return ans; } }; diff --git a/solution/3200-3299/3203.Find Minimum Diameter After Merging Two Trees/Solution.cpp b/solution/3200-3299/3203.Find Minimum Diameter After Merging Two Trees/Solution.cpp index c8b1ca3566545..61fc7bf5d8b77 100644 --- a/solution/3200-3299/3203.Find Minimum Diameter After Merging Two Trees/Solution.cpp +++ b/solution/3200-3299/3203.Find Minimum Diameter After Merging Two Trees/Solution.cpp @@ -15,10 +15,10 @@ class Solution { g[b].push_back(a); } int ans = 0, a = 0; - auto dfs = [&](auto&& dfs, int i, int fa, int t) -> void { + auto dfs = [&](this auto&& dfs, int i, int fa, int t) -> void { for (int j : g[i]) { if (j != fa) { - dfs(dfs, j, i, t + 1); + dfs(j, i, t + 1); } } if (ans < t) { @@ -26,8 +26,8 @@ class Solution { a = i; } }; - dfs(dfs, 0, -1, 0); - dfs(dfs, a, -1, 0); + dfs(0, -1, 0); + dfs(a, -1, 0); return ans; } -}; \ No newline at end of file +}; diff --git a/solution/3200-3299/3205.Maximum Array Hopping Score I/README.md b/solution/3200-3299/3205.Maximum Array Hopping Score I/README.md index c37847f6587bd..c8895686952db 100644 --- a/solution/3200-3299/3205.Maximum Array Hopping Score I/README.md +++ b/solution/3200-3299/3205.Maximum Array Hopping Score I/README.md @@ -136,16 +136,16 @@ public: int maxScore(vector& nums) { int n = nums.size(); vector f(n); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (f[i]) { return f[i]; } for (int j = i + 1; j < n; ++j) { - f[i] = max(f[i], (j - i) * nums[j] + dfs(dfs, j)); + f[i] = max(f[i], (j - i) * nums[j] + dfs(j)); } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; ``` diff --git a/solution/3200-3299/3205.Maximum Array Hopping Score I/README_EN.md b/solution/3200-3299/3205.Maximum Array Hopping Score I/README_EN.md index 1ce14013d7b5e..8371e69b2378c 100644 --- a/solution/3200-3299/3205.Maximum Array Hopping Score I/README_EN.md +++ b/solution/3200-3299/3205.Maximum Array Hopping Score I/README_EN.md @@ -134,16 +134,16 @@ public: int maxScore(vector& nums) { int n = nums.size(); vector f(n); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (f[i]) { return f[i]; } for (int j = i + 1; j < n; ++j) { - f[i] = max(f[i], (j - i) * nums[j] + dfs(dfs, j)); + f[i] = max(f[i], (j - i) * nums[j] + dfs(j)); } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; ``` diff --git a/solution/3200-3299/3205.Maximum Array Hopping Score I/Solution.cpp b/solution/3200-3299/3205.Maximum Array Hopping Score I/Solution.cpp index 69edd5d87fff1..7e841e20eae48 100644 --- a/solution/3200-3299/3205.Maximum Array Hopping Score I/Solution.cpp +++ b/solution/3200-3299/3205.Maximum Array Hopping Score I/Solution.cpp @@ -3,15 +3,15 @@ class Solution { int maxScore(vector& nums) { int n = nums.size(); vector f(n); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (f[i]) { return f[i]; } for (int j = i + 1; j < n; ++j) { - f[i] = max(f[i], (j - i) * nums[j] + dfs(dfs, j)); + f[i] = max(f[i], (j - i) * nums[j] + dfs(j)); } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } -}; \ No newline at end of file +}; diff --git a/solution/3200-3299/3211.Generate Binary Strings Without Adjacent Zeros/README.md b/solution/3200-3299/3211.Generate Binary Strings Without Adjacent Zeros/README.md index 423f5f74d7d77..08f1b085b28ff 100644 --- a/solution/3200-3299/3211.Generate Binary Strings Without Adjacent Zeros/README.md +++ b/solution/3200-3299/3211.Generate Binary Strings Without Adjacent Zeros/README.md @@ -133,7 +133,7 @@ public: vector validStrings(int n) { vector ans; string t; - auto dfs = [&](auto&& dfs, int i) { + auto dfs = [&](this auto&& dfs, int i) { if (i >= n) { ans.emplace_back(t); return; @@ -141,12 +141,12 @@ public: for (int j = 0; j < 2; ++j) { if ((j == 0 && (i == 0 || t[i - 1] == '1')) || j == 1) { t.push_back('0' + j); - dfs(dfs, i + 1); + dfs(i + 1); t.pop_back(); } } }; - dfs(dfs, 0); + dfs(0); return ans; } }; diff --git a/solution/3200-3299/3211.Generate Binary Strings Without Adjacent Zeros/README_EN.md b/solution/3200-3299/3211.Generate Binary Strings Without Adjacent Zeros/README_EN.md index 03a3096a6ac5e..28823e67f6aaf 100644 --- a/solution/3200-3299/3211.Generate Binary Strings Without Adjacent Zeros/README_EN.md +++ b/solution/3200-3299/3211.Generate Binary Strings Without Adjacent Zeros/README_EN.md @@ -131,7 +131,7 @@ public: vector validStrings(int n) { vector ans; string t; - auto dfs = [&](auto&& dfs, int i) { + auto dfs = [&](this auto&& dfs, int i) { if (i >= n) { ans.emplace_back(t); return; @@ -139,12 +139,12 @@ public: for (int j = 0; j < 2; ++j) { if ((j == 0 && (i == 0 || t[i - 1] == '1')) || j == 1) { t.push_back('0' + j); - dfs(dfs, i + 1); + dfs(i + 1); t.pop_back(); } } }; - dfs(dfs, 0); + dfs(0); return ans; } }; diff --git a/solution/3200-3299/3211.Generate Binary Strings Without Adjacent Zeros/Solution.cpp b/solution/3200-3299/3211.Generate Binary Strings Without Adjacent Zeros/Solution.cpp index 8b11f7530f266..72edad4c318b9 100644 --- a/solution/3200-3299/3211.Generate Binary Strings Without Adjacent Zeros/Solution.cpp +++ b/solution/3200-3299/3211.Generate Binary Strings Without Adjacent Zeros/Solution.cpp @@ -3,7 +3,7 @@ class Solution { vector validStrings(int n) { vector ans; string t; - auto dfs = [&](auto&& dfs, int i) { + auto dfs = [&](this auto&& dfs, int i) { if (i >= n) { ans.emplace_back(t); return; @@ -11,12 +11,12 @@ class Solution { for (int j = 0; j < 2; ++j) { if ((j == 0 && (i == 0 || t[i - 1] == '1')) || j == 1) { t.push_back('0' + j); - dfs(dfs, i + 1); + dfs(i + 1); t.pop_back(); } } }; - dfs(dfs, 0); + dfs(0); return ans; } -}; \ No newline at end of file +}; diff --git a/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/README.md b/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/README.md index a550e65326aad..a058176c2cf43 100644 --- a/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/README.md +++ b/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/README.md @@ -279,7 +279,7 @@ public: int n = circles.size(); vector vis(n); - auto dfs = [&](auto&& dfs, int i) -> bool { + auto dfs = [&](this auto&& dfs, int i) -> bool { auto c = circles[i]; ll x1 = c[0], y1 = c[1], r1 = c[2]; if (crossRightBottom(x1, y1, r1)) { @@ -296,7 +296,7 @@ public: continue; } if (x1 * r2 + x2 * r1 < (r1 + r2) * xCorner && y1 * r2 + y2 * r1 < (r1 + r2) * yCorner - && dfs(dfs, j)) { + && dfs(j)) { return true; } } @@ -309,7 +309,7 @@ public: if (inCircle(0, 0, x, y, r) || inCircle(xCorner, yCorner, x, y, r)) { return false; } - if (!vis[i] && crossLeftTop(x, y, r) && dfs(dfs, i)) { + if (!vis[i] && crossLeftTop(x, y, r) && dfs(i)) { return false; } } diff --git a/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/README_EN.md b/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/README_EN.md index 877eab3ddd83e..acf2f2ebc8495 100644 --- a/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/README_EN.md +++ b/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/README_EN.md @@ -277,7 +277,7 @@ public: int n = circles.size(); vector vis(n); - auto dfs = [&](auto&& dfs, int i) -> bool { + auto dfs = [&](this auto&& dfs, int i) -> bool { auto c = circles[i]; ll x1 = c[0], y1 = c[1], r1 = c[2]; if (crossRightBottom(x1, y1, r1)) { @@ -294,7 +294,7 @@ public: continue; } if (x1 * r2 + x2 * r1 < (r1 + r2) * xCorner && y1 * r2 + y2 * r1 < (r1 + r2) * yCorner - && dfs(dfs, j)) { + && dfs(j)) { return true; } } @@ -307,7 +307,7 @@ public: if (inCircle(0, 0, x, y, r) || inCircle(xCorner, yCorner, x, y, r)) { return false; } - if (!vis[i] && crossLeftTop(x, y, r) && dfs(dfs, i)) { + if (!vis[i] && crossLeftTop(x, y, r) && dfs(i)) { return false; } } diff --git a/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/Solution.cpp b/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/Solution.cpp index d705f9722c48f..f7e2723a35602 100644 --- a/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/Solution.cpp +++ b/solution/3200-3299/3235.Check if the Rectangle Corner Is Reachable/Solution.cpp @@ -18,7 +18,7 @@ class Solution { int n = circles.size(); vector vis(n); - auto dfs = [&](auto&& dfs, int i) -> bool { + auto dfs = [&](this auto&& dfs, int i) -> bool { auto c = circles[i]; ll x1 = c[0], y1 = c[1], r1 = c[2]; if (crossRightBottom(x1, y1, r1)) { @@ -35,7 +35,7 @@ class Solution { continue; } if (x1 * r2 + x2 * r1 < (r1 + r2) * xCorner && y1 * r2 + y2 * r1 < (r1 + r2) * yCorner - && dfs(dfs, j)) { + && dfs(j)) { return true; } } @@ -48,7 +48,7 @@ class Solution { if (inCircle(0, 0, x, y, r) || inCircle(xCorner, yCorner, x, y, r)) { return false; } - if (!vis[i] && crossLeftTop(x, y, r) && dfs(dfs, i)) { + if (!vis[i] && crossLeftTop(x, y, r) && dfs(i)) { return false; } } diff --git a/solution/3200-3299/3249.Count the Number of Good Nodes/README.md b/solution/3200-3299/3249.Count the Number of Good Nodes/README.md index cbd854485cbb8..71b112dae51e8 100644 --- a/solution/3200-3299/3249.Count the Number of Good Nodes/README.md +++ b/solution/3200-3299/3249.Count the Number of Good Nodes/README.md @@ -185,11 +185,11 @@ public: g[b].push_back(a); } int ans = 0; - auto dfs = [&](auto&& dfs, int a, int fa) -> int { + auto dfs = [&](this auto&& dfs, int a, int fa) -> int { int pre = -1, cnt = 1, ok = 1; for (int b : g[a]) { if (b != fa) { - int cur = dfs(dfs, b, a); + int cur = dfs(b, a); cnt += cur; if (pre < 0) { pre = cur; @@ -201,7 +201,7 @@ public: ans += ok; return cnt; }; - dfs(dfs, 0, -1); + dfs(0, -1); return ans; } }; diff --git a/solution/3200-3299/3249.Count the Number of Good Nodes/README_EN.md b/solution/3200-3299/3249.Count the Number of Good Nodes/README_EN.md index 572f31e278da8..ea8009ecb063e 100644 --- a/solution/3200-3299/3249.Count the Number of Good Nodes/README_EN.md +++ b/solution/3200-3299/3249.Count the Number of Good Nodes/README_EN.md @@ -181,11 +181,11 @@ public: g[b].push_back(a); } int ans = 0; - auto dfs = [&](auto&& dfs, int a, int fa) -> int { + auto dfs = [&](this auto&& dfs, int a, int fa) -> int { int pre = -1, cnt = 1, ok = 1; for (int b : g[a]) { if (b != fa) { - int cur = dfs(dfs, b, a); + int cur = dfs(b, a); cnt += cur; if (pre < 0) { pre = cur; @@ -197,7 +197,7 @@ public: ans += ok; return cnt; }; - dfs(dfs, 0, -1); + dfs(0, -1); return ans; } }; diff --git a/solution/3200-3299/3249.Count the Number of Good Nodes/Solution.cpp b/solution/3200-3299/3249.Count the Number of Good Nodes/Solution.cpp index 73189db599497..a18e9db13a766 100644 --- a/solution/3200-3299/3249.Count the Number of Good Nodes/Solution.cpp +++ b/solution/3200-3299/3249.Count the Number of Good Nodes/Solution.cpp @@ -9,11 +9,11 @@ class Solution { g[b].push_back(a); } int ans = 0; - auto dfs = [&](auto&& dfs, int a, int fa) -> int { + auto dfs = [&](this auto&& dfs, int a, int fa) -> int { int pre = -1, cnt = 1, ok = 1; for (int b : g[a]) { if (b != fa) { - int cur = dfs(dfs, b, a); + int cur = dfs(b, a); cnt += cur; if (pre < 0) { pre = cur; @@ -25,7 +25,7 @@ class Solution { ans += ok; return cnt; }; - dfs(dfs, 0, -1); + dfs(0, -1); return ans; } }; diff --git a/solution/3200-3299/3253.Construct String with Minimum Cost (Easy)/README.md b/solution/3200-3299/3253.Construct String with Minimum Cost (Easy)/README.md index b0128e3700177..5ecb2c9178ff1 100644 --- a/solution/3200-3299/3253.Construct String with Minimum Cost (Easy)/README.md +++ b/solution/3200-3299/3253.Construct String with Minimum Cost (Easy)/README.md @@ -223,7 +223,7 @@ public: int n = target.length(); int f[n]; memset(f, 0, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } @@ -238,11 +238,11 @@ public: return f[i]; } node = node->children[idx]; - f[i] = min(f[i], node->cost + dfs(dfs, j + 1)); + f[i] = min(f[i], node->cost + dfs(j + 1)); } return f[i]; }; - int ans = dfs(dfs, 0); + int ans = dfs(0); return ans < inf ? ans : -1; } }; diff --git a/solution/3200-3299/3253.Construct String with Minimum Cost (Easy)/README_EN.md b/solution/3200-3299/3253.Construct String with Minimum Cost (Easy)/README_EN.md index b5af739ba1c68..39493be3138d9 100644 --- a/solution/3200-3299/3253.Construct String with Minimum Cost (Easy)/README_EN.md +++ b/solution/3200-3299/3253.Construct String with Minimum Cost (Easy)/README_EN.md @@ -227,7 +227,7 @@ public: int n = target.length(); int f[n]; memset(f, 0, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } @@ -242,11 +242,11 @@ public: return f[i]; } node = node->children[idx]; - f[i] = min(f[i], node->cost + dfs(dfs, j + 1)); + f[i] = min(f[i], node->cost + dfs(j + 1)); } return f[i]; }; - int ans = dfs(dfs, 0); + int ans = dfs(0); return ans < inf ? ans : -1; } }; diff --git a/solution/3200-3299/3253.Construct String with Minimum Cost (Easy)/Solution.cpp b/solution/3200-3299/3253.Construct String with Minimum Cost (Easy)/Solution.cpp index 66e33c7b7856c..05b75fe5a289a 100644 --- a/solution/3200-3299/3253.Construct String with Minimum Cost (Easy)/Solution.cpp +++ b/solution/3200-3299/3253.Construct String with Minimum Cost (Easy)/Solution.cpp @@ -28,7 +28,7 @@ class Solution { int n = target.length(); int f[n]; memset(f, 0, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } @@ -43,11 +43,11 @@ class Solution { return f[i]; } node = node->children[idx]; - f[i] = min(f[i], node->cost + dfs(dfs, j + 1)); + f[i] = min(f[i], node->cost + dfs(j + 1)); } return f[i]; }; - int ans = dfs(dfs, 0); + int ans = dfs(0); return ans < inf ? ans : -1; } }; diff --git a/solution/3200-3299/3283.Maximum Number of Moves to Kill All Pawns/README.md b/solution/3200-3299/3283.Maximum Number of Moves to Kill All Pawns/README.md index 9219676ec95ec..4f9e2ef01bf0c 100644 --- a/solution/3200-3299/3283.Maximum Number of Moves to Kill All Pawns/README.md +++ b/solution/3200-3299/3283.Maximum Number of Moves to Kill All Pawns/README.md @@ -270,7 +270,7 @@ public: int f[n + 1][1 << n][2]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int last, int state, int k) -> int { + auto dfs = [&](this auto&& dfs, int last, int state, int k) -> int { if (state == 0) { return 0; } @@ -282,7 +282,7 @@ public: for (int i = 0; i < positions.size(); ++i) { int x = positions[i][0], y = positions[i][1]; if ((state >> i) & 1) { - int t = dfs(dfs, i, state ^ (1 << i), k ^ 1) + dist[last][x][y]; + int t = dfs(i, state ^ (1 << i), k ^ 1) + dist[last][x][y]; if (k == 1) { res = max(res, t); } else { @@ -292,7 +292,7 @@ public: } return f[last][state][k] = res; }; - return dfs(dfs, n, (1 << n) - 1, 1); + return dfs(n, (1 << n) - 1, 1); } }; ``` diff --git a/solution/3200-3299/3283.Maximum Number of Moves to Kill All Pawns/README_EN.md b/solution/3200-3299/3283.Maximum Number of Moves to Kill All Pawns/README_EN.md index 77f307db3f7f1..99bc9f3e1207a 100644 --- a/solution/3200-3299/3283.Maximum Number of Moves to Kill All Pawns/README_EN.md +++ b/solution/3200-3299/3283.Maximum Number of Moves to Kill All Pawns/README_EN.md @@ -268,7 +268,7 @@ public: int f[n + 1][1 << n][2]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int last, int state, int k) -> int { + auto dfs = [&](this auto&& dfs, int last, int state, int k) -> int { if (state == 0) { return 0; } @@ -280,7 +280,7 @@ public: for (int i = 0; i < positions.size(); ++i) { int x = positions[i][0], y = positions[i][1]; if ((state >> i) & 1) { - int t = dfs(dfs, i, state ^ (1 << i), k ^ 1) + dist[last][x][y]; + int t = dfs(i, state ^ (1 << i), k ^ 1) + dist[last][x][y]; if (k == 1) { res = max(res, t); } else { @@ -290,7 +290,7 @@ public: } return f[last][state][k] = res; }; - return dfs(dfs, n, (1 << n) - 1, 1); + return dfs(n, (1 << n) - 1, 1); } }; ``` diff --git a/solution/3200-3299/3283.Maximum Number of Moves to Kill All Pawns/Solution.cpp b/solution/3200-3299/3283.Maximum Number of Moves to Kill All Pawns/Solution.cpp index 0c199646fcf66..04a13b7d464e2 100644 --- a/solution/3200-3299/3283.Maximum Number of Moves to Kill All Pawns/Solution.cpp +++ b/solution/3200-3299/3283.Maximum Number of Moves to Kill All Pawns/Solution.cpp @@ -30,7 +30,7 @@ class Solution { int f[n + 1][1 << n][2]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int last, int state, int k) -> int { + auto dfs = [&](this auto&& dfs, int last, int state, int k) -> int { if (state == 0) { return 0; } @@ -42,7 +42,7 @@ class Solution { for (int i = 0; i < positions.size(); ++i) { int x = positions[i][0], y = positions[i][1]; if ((state >> i) & 1) { - int t = dfs(dfs, i, state ^ (1 << i), k ^ 1) + dist[last][x][y]; + int t = dfs(i, state ^ (1 << i), k ^ 1) + dist[last][x][y]; if (k == 1) { res = max(res, t); } else { @@ -52,6 +52,6 @@ class Solution { } return f[last][state][k] = res; }; - return dfs(dfs, n, (1 << n) - 1, 1); + return dfs(n, (1 << n) - 1, 1); } }; diff --git a/solution/3200-3299/3290.Maximum Multiplication Score/README.md b/solution/3200-3299/3290.Maximum Multiplication Score/README.md index 963212fd27fa6..07fa173886cc1 100644 --- a/solution/3200-3299/3290.Maximum Multiplication Score/README.md +++ b/solution/3200-3299/3290.Maximum Multiplication Score/README.md @@ -136,7 +136,7 @@ public: int m = a.size(), n = b.size(); long long f[m][n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int j) -> long long { + auto dfs = [&](this auto&& dfs, int i, int j) -> long long { if (j >= n) { return i >= m ? 0 : LLONG_MIN / 2; } @@ -146,9 +146,9 @@ public: if (f[i][j] != -1) { return f[i][j]; } - return f[i][j] = max(dfs(dfs, i, j + 1), 1LL * a[i] * b[j] + dfs(dfs, i + 1, j + 1)); + return f[i][j] = max(dfs(i, j + 1), 1LL * a[i] * b[j] + dfs(i + 1, j + 1)); }; - return dfs(dfs, 0, 0); + return dfs(0, 0); } }; ``` diff --git a/solution/3200-3299/3290.Maximum Multiplication Score/README_EN.md b/solution/3200-3299/3290.Maximum Multiplication Score/README_EN.md index a0375cb018120..01d2577fba1f4 100644 --- a/solution/3200-3299/3290.Maximum Multiplication Score/README_EN.md +++ b/solution/3200-3299/3290.Maximum Multiplication Score/README_EN.md @@ -134,7 +134,7 @@ public: int m = a.size(), n = b.size(); long long f[m][n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int j) -> long long { + auto dfs = [&](this auto&& dfs, int i, int j) -> long long { if (j >= n) { return i >= m ? 0 : LLONG_MIN / 2; } @@ -144,9 +144,9 @@ public: if (f[i][j] != -1) { return f[i][j]; } - return f[i][j] = max(dfs(dfs, i, j + 1), 1LL * a[i] * b[j] + dfs(dfs, i + 1, j + 1)); + return f[i][j] = max(dfs(i, j + 1), 1LL * a[i] * b[j] + dfs(i + 1, j + 1)); }; - return dfs(dfs, 0, 0); + return dfs(0, 0); } }; ``` diff --git a/solution/3200-3299/3290.Maximum Multiplication Score/Solution.cpp b/solution/3200-3299/3290.Maximum Multiplication Score/Solution.cpp index 15702306b3f20..d09658b7d3852 100644 --- a/solution/3200-3299/3290.Maximum Multiplication Score/Solution.cpp +++ b/solution/3200-3299/3290.Maximum Multiplication Score/Solution.cpp @@ -4,7 +4,7 @@ class Solution { int m = a.size(), n = b.size(); long long f[m][n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int j) -> long long { + auto dfs = [&](this auto&& dfs, int i, int j) -> long long { if (j >= n) { return i >= m ? 0 : LLONG_MIN / 2; } @@ -14,8 +14,8 @@ class Solution { if (f[i][j] != -1) { return f[i][j]; } - return f[i][j] = max(dfs(dfs, i, j + 1), 1LL * a[i] * b[j] + dfs(dfs, i + 1, j + 1)); + return f[i][j] = max(dfs(i, j + 1), 1LL * a[i] * b[j] + dfs(i + 1, j + 1)); }; - return dfs(dfs, 0, 0); + return dfs(0, 0); } }; diff --git a/solution/3200-3299/3291.Minimum Number of Valid Strings to Form Target I/README.md b/solution/3200-3299/3291.Minimum Number of Valid Strings to Form Target I/README.md index afe8687ccfd23..89ad612cf47f5 100644 --- a/solution/3200-3299/3291.Minimum Number of Valid Strings to Form Target I/README.md +++ b/solution/3200-3299/3291.Minimum Number of Valid Strings to Form Target I/README.md @@ -243,7 +243,7 @@ public: const int inf = 1 << 30; int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } @@ -258,11 +258,11 @@ public: break; } node = node->children[k]; - f[i] = min(f[i], 1 + dfs(dfs, j + 1)); + f[i] = min(f[i], 1 + dfs(j + 1)); } return f[i]; }; - int ans = dfs(dfs, 0); + int ans = dfs(0); return ans < inf ? ans : -1; } }; diff --git a/solution/3200-3299/3291.Minimum Number of Valid Strings to Form Target I/README_EN.md b/solution/3200-3299/3291.Minimum Number of Valid Strings to Form Target I/README_EN.md index 9d0cbf382833d..7d4021d34a634 100644 --- a/solution/3200-3299/3291.Minimum Number of Valid Strings to Form Target I/README_EN.md +++ b/solution/3200-3299/3291.Minimum Number of Valid Strings to Form Target I/README_EN.md @@ -241,7 +241,7 @@ public: const int inf = 1 << 30; int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } @@ -256,11 +256,11 @@ public: break; } node = node->children[k]; - f[i] = min(f[i], 1 + dfs(dfs, j + 1)); + f[i] = min(f[i], 1 + dfs(j + 1)); } return f[i]; }; - int ans = dfs(dfs, 0); + int ans = dfs(0); return ans < inf ? ans : -1; } }; diff --git a/solution/3200-3299/3291.Minimum Number of Valid Strings to Form Target I/Solution.cpp b/solution/3200-3299/3291.Minimum Number of Valid Strings to Form Target I/Solution.cpp index 5bee2eb40f24c..7b6e1d8838ad9 100644 --- a/solution/3200-3299/3291.Minimum Number of Valid Strings to Form Target I/Solution.cpp +++ b/solution/3200-3299/3291.Minimum Number of Valid Strings to Form Target I/Solution.cpp @@ -25,7 +25,7 @@ class Solution { const int inf = 1 << 30; int f[n]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i >= n) { return 0; } @@ -40,11 +40,11 @@ class Solution { break; } node = node->children[k]; - f[i] = min(f[i], 1 + dfs(dfs, j + 1)); + f[i] = min(f[i], 1 + dfs(j + 1)); } return f[i]; }; - int ans = dfs(dfs, 0); + int ans = dfs(0); return ans < inf ? ans : -1; } }; diff --git a/solution/3300-3399/3310.Remove Methods From Project/README.md b/solution/3300-3399/3310.Remove Methods From Project/README.md index 7146246f7919c..29f37486f81ee 100644 --- a/solution/3300-3399/3310.Remove Methods From Project/README.md +++ b/solution/3300-3399/3310.Remove Methods From Project/README.md @@ -213,27 +213,27 @@ public: f[b].push_back(a); g[a].push_back(b); } - auto dfs = [&](auto&& dfs, int i) -> void { + auto dfs = [&](this auto&& dfs, int i) -> void { suspicious[i] = true; for (int j : g[i]) { if (!suspicious[j]) { - dfs(dfs, j); + dfs(j); } } }; - dfs(dfs, k); - auto dfs2 = [&](auto&& dfs2, int i) -> void { + dfs(k); + auto dfs2 = [&](this auto&& dfs2, int i) -> void { vis[i] = true; for (int j : f[i]) { if (!vis[j]) { suspicious[j] = false; - dfs2(dfs2, j); + dfs2(j); } } }; for (int i = 0; i < n; ++i) { if (!suspicious[i] && !vis[i]) { - dfs2(dfs2, i); + dfs2(i); } } vector ans; diff --git a/solution/3300-3399/3310.Remove Methods From Project/README_EN.md b/solution/3300-3399/3310.Remove Methods From Project/README_EN.md index 5990a503ec0d3..08b46562c5c20 100644 --- a/solution/3300-3399/3310.Remove Methods From Project/README_EN.md +++ b/solution/3300-3399/3310.Remove Methods From Project/README_EN.md @@ -211,27 +211,27 @@ public: f[b].push_back(a); g[a].push_back(b); } - auto dfs = [&](auto&& dfs, int i) -> void { + auto dfs = [&](this auto&& dfs, int i) -> void { suspicious[i] = true; for (int j : g[i]) { if (!suspicious[j]) { - dfs(dfs, j); + dfs(j); } } }; - dfs(dfs, k); - auto dfs2 = [&](auto&& dfs2, int i) -> void { + dfs(k); + auto dfs2 = [&](this auto&& dfs2, int i) -> void { vis[i] = true; for (int j : f[i]) { if (!vis[j]) { suspicious[j] = false; - dfs2(dfs2, j); + dfs2(j); } } }; for (int i = 0; i < n; ++i) { if (!suspicious[i] && !vis[i]) { - dfs2(dfs2, i); + dfs2(i); } } vector ans; diff --git a/solution/3300-3399/3310.Remove Methods From Project/Solution.cpp b/solution/3300-3399/3310.Remove Methods From Project/Solution.cpp index 006de700c1cf1..0d700b8e11319 100644 --- a/solution/3300-3399/3310.Remove Methods From Project/Solution.cpp +++ b/solution/3300-3399/3310.Remove Methods From Project/Solution.cpp @@ -11,27 +11,27 @@ class Solution { f[b].push_back(a); g[a].push_back(b); } - auto dfs = [&](auto&& dfs, int i) -> void { + auto dfs = [&](this auto&& dfs, int i) -> void { suspicious[i] = true; for (int j : g[i]) { if (!suspicious[j]) { - dfs(dfs, j); + dfs(j); } } }; - dfs(dfs, k); - auto dfs2 = [&](auto&& dfs2, int i) -> void { + dfs(k); + auto dfs2 = [&](this auto&& dfs2, int i) -> void { vis[i] = true; for (int j : f[i]) { if (!vis[j]) { suspicious[j] = false; - dfs2(dfs2, j); + dfs2(j); } } }; for (int i = 0; i < n; ++i) { if (!suspicious[i] && !vis[i]) { - dfs2(dfs2, i); + dfs2(i); } } vector ans; diff --git a/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README.md b/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README.md index 7b19c8e24268c..0268412149161 100644 --- a/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README.md +++ b/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README.md @@ -199,12 +199,12 @@ class Solution { public: int kthLargestPerfectSubtree(TreeNode* root, int k) { vector nums; - auto dfs = [&](auto&& dfs, TreeNode* root) -> int { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> int { if (!root) { return 0; } - int l = dfs(dfs, root->left); - int r = dfs(dfs, root->right); + int l = dfs(root->left); + int r = dfs(root->right); if (l < 0 || l != r) { return -1; } @@ -212,7 +212,7 @@ public: nums.push_back(cnt); return cnt; }; - dfs(dfs, root); + dfs(root); if (nums.size() < k) { return -1; } diff --git a/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README_EN.md b/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README_EN.md index 056e565492d2f..ab1cb29d9a87a 100644 --- a/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README_EN.md +++ b/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README_EN.md @@ -197,12 +197,12 @@ class Solution { public: int kthLargestPerfectSubtree(TreeNode* root, int k) { vector nums; - auto dfs = [&](auto&& dfs, TreeNode* root) -> int { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> int { if (!root) { return 0; } - int l = dfs(dfs, root->left); - int r = dfs(dfs, root->right); + int l = dfs(root->left); + int r = dfs(root->right); if (l < 0 || l != r) { return -1; } @@ -210,7 +210,7 @@ public: nums.push_back(cnt); return cnt; }; - dfs(dfs, root); + dfs(root); if (nums.size() < k) { return -1; } diff --git a/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/Solution.cpp b/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/Solution.cpp index b39240437ccb8..de66bb937d67b 100644 --- a/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/Solution.cpp +++ b/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/Solution.cpp @@ -13,12 +13,12 @@ class Solution { public: int kthLargestPerfectSubtree(TreeNode* root, int k) { vector nums; - auto dfs = [&](auto&& dfs, TreeNode* root) -> int { + auto dfs = [&](this auto&& dfs, TreeNode* root) -> int { if (!root) { return 0; } - int l = dfs(dfs, root->left); - int r = dfs(dfs, root->right); + int l = dfs(root->left); + int r = dfs(root->right); if (l < 0 || l != r) { return -1; } @@ -26,7 +26,7 @@ class Solution { nums.push_back(cnt); return cnt; }; - dfs(dfs, root); + dfs(root); if (nums.size() < k) { return -1; } diff --git a/solution/3300-3399/3320.Count The Number of Winning Sequences/README.md b/solution/3300-3399/3320.Count The Number of Winning Sequences/README.md index 56bfef572d355..70142d68970d2 100644 --- a/solution/3300-3399/3320.Count The Number of Winning Sequences/README.md +++ b/solution/3300-3399/3320.Count The Number of Winning Sequences/README.md @@ -206,7 +206,7 @@ public: return x == 2 && y == 0 ? -1 : 1; }; const int mod = 1e9 + 7; - auto dfs = [&](auto&& dfs, int i, int j, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> int { if (n - i <= j - n) { return 0; } @@ -221,11 +221,11 @@ public: if (l == k) { continue; } - ans = (ans + dfs(dfs, i + 1, j + calc(d[s[i] - 'A'], l), l)) % mod; + ans = (ans + dfs(i + 1, j + calc(d[s[i] - 'A'], l), l)) % mod; } return f[i][j][k] = ans; }; - return dfs(dfs, 0, n, 3); + return dfs(0, n, 3); } }; ``` diff --git a/solution/3300-3399/3320.Count The Number of Winning Sequences/README_EN.md b/solution/3300-3399/3320.Count The Number of Winning Sequences/README_EN.md index 444532f2a68b6..b83d74cac3760 100644 --- a/solution/3300-3399/3320.Count The Number of Winning Sequences/README_EN.md +++ b/solution/3300-3399/3320.Count The Number of Winning Sequences/README_EN.md @@ -203,7 +203,7 @@ public: return x == 2 && y == 0 ? -1 : 1; }; const int mod = 1e9 + 7; - auto dfs = [&](auto&& dfs, int i, int j, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> int { if (n - i <= j - n) { return 0; } @@ -218,11 +218,11 @@ public: if (l == k) { continue; } - ans = (ans + dfs(dfs, i + 1, j + calc(d[s[i] - 'A'], l), l)) % mod; + ans = (ans + dfs(i + 1, j + calc(d[s[i] - 'A'], l), l)) % mod; } return f[i][j][k] = ans; }; - return dfs(dfs, 0, n, 3); + return dfs(0, n, 3); } }; ``` diff --git a/solution/3300-3399/3320.Count The Number of Winning Sequences/Solution.cpp b/solution/3300-3399/3320.Count The Number of Winning Sequences/Solution.cpp index e438deba1d812..7565140182e2d 100644 --- a/solution/3300-3399/3320.Count The Number of Winning Sequences/Solution.cpp +++ b/solution/3300-3399/3320.Count The Number of Winning Sequences/Solution.cpp @@ -17,7 +17,7 @@ class Solution { return x == 2 && y == 0 ? -1 : 1; }; const int mod = 1e9 + 7; - auto dfs = [&](auto&& dfs, int i, int j, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> int { if (n - i <= j - n) { return 0; } @@ -32,10 +32,10 @@ class Solution { if (l == k) { continue; } - ans = (ans + dfs(dfs, i + 1, j + calc(d[s[i] - 'A'], l), l)) % mod; + ans = (ans + dfs(i + 1, j + calc(d[s[i] - 'A'], l), l)) % mod; } return f[i][j][k] = ans; }; - return dfs(dfs, 0, n, 3); + return dfs(0, n, 3); } }; diff --git a/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README.md b/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README.md index 9ed9cae91e589..65901c8f6aeb0 100644 --- a/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README.md +++ b/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README.md @@ -266,16 +266,16 @@ public: } string dfsStr; vector> pos(n); - auto dfs = [&](auto&& dfs, int i) -> void { + auto dfs = [&](this auto&& dfs, int i) -> void { int l = dfsStr.size() + 1; for (int j : g[i]) { - dfs(dfs, j); + dfs(j); } dfsStr.push_back(s[i]); int r = dfsStr.size(); pos[i] = {l, r}; }; - dfs(dfs, 0); + dfs(0); const int base = 13331; const int mod = 998244353; diff --git a/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README_EN.md b/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README_EN.md index 1333ab1327add..3db1aab7bfdf6 100644 --- a/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README_EN.md +++ b/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README_EN.md @@ -259,16 +259,16 @@ public: } string dfsStr; vector> pos(n); - auto dfs = [&](auto&& dfs, int i) -> void { + auto dfs = [&](this auto&& dfs, int i) -> void { int l = dfsStr.size() + 1; for (int j : g[i]) { - dfs(dfs, j); + dfs(j); } dfsStr.push_back(s[i]); int r = dfsStr.size(); pos[i] = {l, r}; }; - dfs(dfs, 0); + dfs(0); const int base = 13331; const int mod = 998244353; diff --git a/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/Solution.cpp b/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/Solution.cpp index af3e8ef56243b..dfb01b57e0b81 100644 --- a/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/Solution.cpp +++ b/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/Solution.cpp @@ -32,16 +32,16 @@ class Solution { } string dfsStr; vector> pos(n); - auto dfs = [&](auto&& dfs, int i) -> void { + auto dfs = [&](this auto&& dfs, int i) -> void { int l = dfsStr.size() + 1; for (int j : g[i]) { - dfs(dfs, j); + dfs(j); } dfsStr.push_back(s[i]); int r = dfsStr.size(); pos[i] = {l, r}; }; - dfs(dfs, 0); + dfs(0); const int base = 13331; const int mod = 998244353; diff --git a/solution/3300-3399/3331.Find Subtree Sizes After Changes/README.md b/solution/3300-3399/3331.Find Subtree Sizes After Changes/README.md index 45655238350a7..7717aae6c32fe 100644 --- a/solution/3300-3399/3331.Find Subtree Sizes After Changes/README.md +++ b/solution/3300-3399/3331.Find Subtree Sizes After Changes/README.md @@ -174,12 +174,12 @@ public: g[parent[i]].push_back(i); } vector ans(n); - auto dfs = [&](auto&& dfs, int i, int fa) -> void { + auto dfs = [&](this auto&& dfs, int i, int fa) -> void { ans[i] = 1; int idx = s[i] - 'a'; d[idx].push_back(i); for (int j : g[i]) { - dfs(dfs, j, i); + dfs(j, i); } int k = d[idx].size() > 1 ? d[idx][d[idx].size() - 2] : fa; if (k >= 0) { @@ -187,7 +187,7 @@ public: } d[idx].pop_back(); }; - dfs(dfs, 0, -1); + dfs(0, -1); return ans; } }; diff --git a/solution/3300-3399/3331.Find Subtree Sizes After Changes/README_EN.md b/solution/3300-3399/3331.Find Subtree Sizes After Changes/README_EN.md index c3a3810b5462e..12f81fe6bab64 100644 --- a/solution/3300-3399/3331.Find Subtree Sizes After Changes/README_EN.md +++ b/solution/3300-3399/3331.Find Subtree Sizes After Changes/README_EN.md @@ -168,12 +168,12 @@ public: g[parent[i]].push_back(i); } vector ans(n); - auto dfs = [&](auto&& dfs, int i, int fa) -> void { + auto dfs = [&](this auto&& dfs, int i, int fa) -> void { ans[i] = 1; int idx = s[i] - 'a'; d[idx].push_back(i); for (int j : g[i]) { - dfs(dfs, j, i); + dfs(j, i); } int k = d[idx].size() > 1 ? d[idx][d[idx].size() - 2] : fa; if (k >= 0) { @@ -181,7 +181,7 @@ public: } d[idx].pop_back(); }; - dfs(dfs, 0, -1); + dfs(0, -1); return ans; } }; diff --git a/solution/3300-3399/3331.Find Subtree Sizes After Changes/Solution.cpp b/solution/3300-3399/3331.Find Subtree Sizes After Changes/Solution.cpp index 9a4cea0da70be..c83b7785680a5 100644 --- a/solution/3300-3399/3331.Find Subtree Sizes After Changes/Solution.cpp +++ b/solution/3300-3399/3331.Find Subtree Sizes After Changes/Solution.cpp @@ -8,12 +8,12 @@ class Solution { g[parent[i]].push_back(i); } vector ans(n); - auto dfs = [&](auto&& dfs, int i, int fa) -> void { + auto dfs = [&](this auto&& dfs, int i, int fa) -> void { ans[i] = 1; int idx = s[i] - 'a'; d[idx].push_back(i); for (int j : g[i]) { - dfs(dfs, j, i); + dfs(j, i); } int k = d[idx].size() > 1 ? d[idx][d[idx].size() - 2] : fa; if (k >= 0) { @@ -21,7 +21,7 @@ class Solution { } d[idx].pop_back(); }; - dfs(dfs, 0, -1); + dfs(0, -1); return ans; } }; diff --git a/solution/3300-3399/3339.Find the Number of K-Even Arrays/README.md b/solution/3300-3399/3339.Find the Number of K-Even Arrays/README.md index 97fee5dc0b150..3fcf3ea2355a1 100644 --- a/solution/3300-3399/3339.Find the Number of K-Even Arrays/README.md +++ b/solution/3300-3399/3339.Find the Number of K-Even Arrays/README.md @@ -171,7 +171,7 @@ public: const int mod = 1e9 + 7; int cnt0 = m / 2; int cnt1 = m - cnt0; - auto dfs = [&](auto&& dfs, int i, int j, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> int { if (j < 0) { return 0; } @@ -181,11 +181,11 @@ public: if (f[i][j][k] != -1) { return f[i][j][k]; } - int a = 1LL * cnt1 * dfs(dfs, i + 1, j, 1) % mod; - int b = 1LL * cnt0 * dfs(dfs, i + 1, j - (k & 1 ^ 1), 0) % mod; + int a = 1LL * cnt1 * dfs(i + 1, j, 1) % mod; + int b = 1LL * cnt0 * dfs(i + 1, j - (k & 1 ^ 1), 0) % mod; return f[i][j][k] = (a + b) % mod; }; - return dfs(dfs, 0, k, 1); + return dfs(0, k, 1); } }; ``` diff --git a/solution/3300-3399/3339.Find the Number of K-Even Arrays/README_EN.md b/solution/3300-3399/3339.Find the Number of K-Even Arrays/README_EN.md index 572c259602450..88fee7409d147 100644 --- a/solution/3300-3399/3339.Find the Number of K-Even Arrays/README_EN.md +++ b/solution/3300-3399/3339.Find the Number of K-Even Arrays/README_EN.md @@ -169,7 +169,7 @@ public: const int mod = 1e9 + 7; int cnt0 = m / 2; int cnt1 = m - cnt0; - auto dfs = [&](auto&& dfs, int i, int j, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> int { if (j < 0) { return 0; } @@ -179,11 +179,11 @@ public: if (f[i][j][k] != -1) { return f[i][j][k]; } - int a = 1LL * cnt1 * dfs(dfs, i + 1, j, 1) % mod; - int b = 1LL * cnt0 * dfs(dfs, i + 1, j - (k & 1 ^ 1), 0) % mod; + int a = 1LL * cnt1 * dfs(i + 1, j, 1) % mod; + int b = 1LL * cnt0 * dfs(i + 1, j - (k & 1 ^ 1), 0) % mod; return f[i][j][k] = (a + b) % mod; }; - return dfs(dfs, 0, k, 1); + return dfs(0, k, 1); } }; ``` diff --git a/solution/3300-3399/3339.Find the Number of K-Even Arrays/Solution.cpp b/solution/3300-3399/3339.Find the Number of K-Even Arrays/Solution.cpp index c63fc10ccfb94..69b5c790e49a8 100644 --- a/solution/3300-3399/3339.Find the Number of K-Even Arrays/Solution.cpp +++ b/solution/3300-3399/3339.Find the Number of K-Even Arrays/Solution.cpp @@ -6,7 +6,7 @@ class Solution { const int mod = 1e9 + 7; int cnt0 = m / 2; int cnt1 = m - cnt0; - auto dfs = [&](auto&& dfs, int i, int j, int k) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int k) -> int { if (j < 0) { return 0; } @@ -16,10 +16,10 @@ class Solution { if (f[i][j][k] != -1) { return f[i][j][k]; } - int a = 1LL * cnt1 * dfs(dfs, i + 1, j, 1) % mod; - int b = 1LL * cnt0 * dfs(dfs, i + 1, j - (k & 1 ^ 1), 0) % mod; + int a = 1LL * cnt1 * dfs(i + 1, j, 1) % mod; + int b = 1LL * cnt0 * dfs(i + 1, j - (k & 1 ^ 1), 0) % mod; return f[i][j][k] = (a + b) % mod; }; - return dfs(dfs, 0, k, 1); + return dfs(0, k, 1); } }; diff --git a/solution/3300-3399/3343.Count Number of Balanced Permutations/README.md b/solution/3300-3399/3343.Count Number of Balanced Permutations/README.md index dac4ebcc67205..4686c73888bea 100644 --- a/solution/3300-3399/3343.Count Number of Balanced Permutations/README.md +++ b/solution/3300-3399/3343.Count Number of Balanced Permutations/README.md @@ -229,7 +229,7 @@ public: int m = n / 2 + 1; int f[10][s / 2 + 1][m][m + 1]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int j, int a, int b) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int a, int b) -> int { if (i > 9) { return ((j | a | b) == 0 ? 1 : 0); } @@ -243,13 +243,13 @@ public: for (int l = 0; l <= min(cnt[i], a); ++l) { int r = cnt[i] - l; if (r >= 0 && r <= b && l * i <= j) { - int t = c[a][l] * c[b][r] % MOD * dfs(dfs, i + 1, j - l * i, a - l, b - r) % MOD; + int t = c[a][l] * c[b][r] % MOD * dfs(i + 1, j - l * i, a - l, b - r) % MOD; ans = (ans + t) % MOD; } } return f[i][j][a][b] = ans; }; - return dfs(dfs, 0, s / 2, n / 2, (n + 1) / 2); + return dfs(0, s / 2, n / 2, (n + 1) / 2); } }; ``` diff --git a/solution/3300-3399/3343.Count Number of Balanced Permutations/README_EN.md b/solution/3300-3399/3343.Count Number of Balanced Permutations/README_EN.md index 5c1e5db223468..7a406882a81bc 100644 --- a/solution/3300-3399/3343.Count Number of Balanced Permutations/README_EN.md +++ b/solution/3300-3399/3343.Count Number of Balanced Permutations/README_EN.md @@ -226,7 +226,7 @@ public: int m = n / 2 + 1; int f[10][s / 2 + 1][m][m + 1]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int j, int a, int b) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int a, int b) -> int { if (i > 9) { return ((j | a | b) == 0 ? 1 : 0); } @@ -240,13 +240,13 @@ public: for (int l = 0; l <= min(cnt[i], a); ++l) { int r = cnt[i] - l; if (r >= 0 && r <= b && l * i <= j) { - int t = c[a][l] * c[b][r] % MOD * dfs(dfs, i + 1, j - l * i, a - l, b - r) % MOD; + int t = c[a][l] * c[b][r] % MOD * dfs(i + 1, j - l * i, a - l, b - r) % MOD; ans = (ans + t) % MOD; } } return f[i][j][a][b] = ans; }; - return dfs(dfs, 0, s / 2, n / 2, (n + 1) / 2); + return dfs(0, s / 2, n / 2, (n + 1) / 2); } }; ``` diff --git a/solution/3300-3399/3343.Count Number of Balanced Permutations/Solution.cpp b/solution/3300-3399/3343.Count Number of Balanced Permutations/Solution.cpp index c596d247f6478..f2ed907a3bea5 100644 --- a/solution/3300-3399/3343.Count Number of Balanced Permutations/Solution.cpp +++ b/solution/3300-3399/3343.Count Number of Balanced Permutations/Solution.cpp @@ -30,7 +30,7 @@ class Solution { int m = n / 2 + 1; int f[10][s / 2 + 1][m][m + 1]; memset(f, -1, sizeof(f)); - auto dfs = [&](auto&& dfs, int i, int j, int a, int b) -> int { + auto dfs = [&](this auto&& dfs, int i, int j, int a, int b) -> int { if (i > 9) { return ((j | a | b) == 0 ? 1 : 0); } @@ -44,12 +44,12 @@ class Solution { for (int l = 0; l <= min(cnt[i], a); ++l) { int r = cnt[i] - l; if (r >= 0 && r <= b && l * i <= j) { - int t = c[a][l] * c[b][r] % MOD * dfs(dfs, i + 1, j - l * i, a - l, b - r) % MOD; + int t = c[a][l] * c[b][r] % MOD * dfs(i + 1, j - l * i, a - l, b - r) % MOD; ans = (ans + t) % MOD; } } return f[i][j][a][b] = ans; }; - return dfs(dfs, 0, s / 2, n / 2, (n + 1) / 2); + return dfs(0, s / 2, n / 2, (n + 1) / 2); } }; diff --git a/solution/3300-3399/3367.Maximize Sum of Weights after Edge Removals/README.md b/solution/3300-3399/3367.Maximize Sum of Weights after Edge Removals/README.md index 599300bc54e3e..29d4cd76d4979 100644 --- a/solution/3300-3399/3367.Maximize Sum of Weights after Edge Removals/README.md +++ b/solution/3300-3399/3367.Maximize Sum of Weights after Edge Removals/README.md @@ -175,14 +175,14 @@ public: g[v].emplace_back(u, w); } using ll = long long; - auto dfs = [&](auto&& dfs, int u, int fa) -> pair { + auto dfs = [&](this auto&& dfs, int u, int fa) -> pair { ll s = 0; vector t; for (auto& [v, w] : g[u]) { if (v == fa) { continue; } - auto [a, b] = dfs(dfs, v, u); + auto [a, b] = dfs(v, u); s += a; ll d = w + b - a; if (d > 0) { @@ -196,7 +196,7 @@ public: return {s + (t.size() >= k ? t[k - 1] : 0), s}; }; - auto [x, y] = dfs(dfs, 0, -1); + auto [x, y] = dfs(0, -1); return max(x, y); } }; diff --git a/solution/3300-3399/3367.Maximize Sum of Weights after Edge Removals/README_EN.md b/solution/3300-3399/3367.Maximize Sum of Weights after Edge Removals/README_EN.md index 9177d9e63ef61..ba150e46e1e6d 100644 --- a/solution/3300-3399/3367.Maximize Sum of Weights after Edge Removals/README_EN.md +++ b/solution/3300-3399/3367.Maximize Sum of Weights after Edge Removals/README_EN.md @@ -172,14 +172,14 @@ public: g[v].emplace_back(u, w); } using ll = long long; - auto dfs = [&](auto&& dfs, int u, int fa) -> pair { + auto dfs = [&](this auto&& dfs, int u, int fa) -> pair { ll s = 0; vector t; for (auto& [v, w] : g[u]) { if (v == fa) { continue; } - auto [a, b] = dfs(dfs, v, u); + auto [a, b] = dfs(v, u); s += a; ll d = w + b - a; if (d > 0) { @@ -193,7 +193,7 @@ public: return {s + (t.size() >= k ? t[k - 1] : 0), s}; }; - auto [x, y] = dfs(dfs, 0, -1); + auto [x, y] = dfs(0, -1); return max(x, y); } }; diff --git a/solution/3300-3399/3367.Maximize Sum of Weights after Edge Removals/Solution.cpp b/solution/3300-3399/3367.Maximize Sum of Weights after Edge Removals/Solution.cpp index 043b0f4aac007..e8689446e93e7 100644 --- a/solution/3300-3399/3367.Maximize Sum of Weights after Edge Removals/Solution.cpp +++ b/solution/3300-3399/3367.Maximize Sum of Weights after Edge Removals/Solution.cpp @@ -9,14 +9,14 @@ class Solution { g[v].emplace_back(u, w); } using ll = long long; - auto dfs = [&](auto&& dfs, int u, int fa) -> pair { + auto dfs = [&](this auto&& dfs, int u, int fa) -> pair { ll s = 0; vector t; for (auto& [v, w] : g[u]) { if (v == fa) { continue; } - auto [a, b] = dfs(dfs, v, u); + auto [a, b] = dfs(v, u); s += a; ll d = w + b - a; if (d > 0) { @@ -30,7 +30,7 @@ class Solution { return {s + (t.size() >= k ? t[k - 1] : 0), s}; }; - auto [x, y] = dfs(dfs, 0, -1); + auto [x, y] = dfs(0, -1); return max(x, y); } }; diff --git a/solution/3300-3399/3376.Minimum Time to Break Locks I/README.md b/solution/3300-3399/3376.Minimum Time to Break Locks I/README.md index 34becf51d59a1..6e758ae69f5fe 100644 --- a/solution/3300-3399/3376.Minimum Time to Break Locks I/README.md +++ b/solution/3300-3399/3376.Minimum Time to Break Locks I/README.md @@ -251,7 +251,7 @@ public: int f[1 << n]; memset(f, -1, sizeof(f)); int k = K; - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i == (1 << n) - 1) { return 0; } @@ -263,12 +263,12 @@ public: f[i] = INT_MAX; for (int j = 0; j < n; ++j) { if (i >> j & 1 ^ 1) { - f[i] = min(f[i], dfs(dfs, i | 1 << j) + (strength[j] + x - 1) / x); + f[i] = min(f[i], dfs(i | 1 << j) + (strength[j] + x - 1) / x); } } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; ``` diff --git a/solution/3300-3399/3376.Minimum Time to Break Locks I/README_EN.md b/solution/3300-3399/3376.Minimum Time to Break Locks I/README_EN.md index 2ca40e558bf1a..2d2f508ea6810 100644 --- a/solution/3300-3399/3376.Minimum Time to Break Locks I/README_EN.md +++ b/solution/3300-3399/3376.Minimum Time to Break Locks I/README_EN.md @@ -249,7 +249,7 @@ public: int f[1 << n]; memset(f, -1, sizeof(f)); int k = K; - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i == (1 << n) - 1) { return 0; } @@ -261,12 +261,12 @@ public: f[i] = INT_MAX; for (int j = 0; j < n; ++j) { if (i >> j & 1 ^ 1) { - f[i] = min(f[i], dfs(dfs, i | 1 << j) + (strength[j] + x - 1) / x); + f[i] = min(f[i], dfs(i | 1 << j) + (strength[j] + x - 1) / x); } } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; ``` diff --git a/solution/3300-3399/3376.Minimum Time to Break Locks I/Solution.cpp b/solution/3300-3399/3376.Minimum Time to Break Locks I/Solution.cpp index 94db045d7aac4..628d8321d42d5 100644 --- a/solution/3300-3399/3376.Minimum Time to Break Locks I/Solution.cpp +++ b/solution/3300-3399/3376.Minimum Time to Break Locks I/Solution.cpp @@ -5,7 +5,7 @@ class Solution { int f[1 << n]; memset(f, -1, sizeof(f)); int k = K; - auto dfs = [&](auto&& dfs, int i) -> int { + auto dfs = [&](this auto&& dfs, int i) -> int { if (i == (1 << n) - 1) { return 0; } @@ -17,11 +17,11 @@ class Solution { f[i] = INT_MAX; for (int j = 0; j < n; ++j) { if (i >> j & 1 ^ 1) { - f[i] = min(f[i], dfs(dfs, i | 1 << j) + (strength[j] + x - 1) / x); + f[i] = min(f[i], dfs(i | 1 << j) + (strength[j] + x - 1) / x); } } return f[i]; }; - return dfs(dfs, 0); + return dfs(0); } }; diff --git a/solution/3300-3399/3387.Maximize Amount After Two Days of Conversions/README.md b/solution/3300-3399/3387.Maximize Amount After Two Days of Conversions/README.md index d0c65953f2e38..bf0d1f7f2d320 100644 --- a/solution/3300-3399/3387.Maximize Amount After Two Days of Conversions/README.md +++ b/solution/3300-3399/3387.Maximize Amount After Two Days of Conversions/README.md @@ -236,7 +236,7 @@ private: g[b].push_back({a, 1 / r}); } - auto dfs = [&](auto&& dfs, const string& a, double v) -> void { + auto dfs = [&](this auto&& dfs, const string& a, double v) -> void { if (d.find(a) != d.end()) { return; } @@ -244,11 +244,11 @@ private: d[a] = v; for (const auto& [b, r] : g[a]) { if (d.find(b) == d.end()) { - dfs(dfs, b, v * r); + dfs(b, v * r); } } }; - dfs(dfs, init, 1.0); + dfs(init, 1.0); return d; } }; diff --git a/solution/3300-3399/3387.Maximize Amount After Two Days of Conversions/README_EN.md b/solution/3300-3399/3387.Maximize Amount After Two Days of Conversions/README_EN.md index 3886a097ace8c..d19069b20b531 100644 --- a/solution/3300-3399/3387.Maximize Amount After Two Days of Conversions/README_EN.md +++ b/solution/3300-3399/3387.Maximize Amount After Two Days of Conversions/README_EN.md @@ -232,7 +232,7 @@ private: g[b].push_back({a, 1 / r}); } - auto dfs = [&](auto&& dfs, const string& a, double v) -> void { + auto dfs = [&](this auto&& dfs, const string& a, double v) -> void { if (d.find(a) != d.end()) { return; } @@ -240,11 +240,11 @@ private: d[a] = v; for (const auto& [b, r] : g[a]) { if (d.find(b) == d.end()) { - dfs(dfs, b, v * r); + dfs(b, v * r); } } }; - dfs(dfs, init, 1.0); + dfs(init, 1.0); return d; } }; diff --git a/solution/3300-3399/3387.Maximize Amount After Two Days of Conversions/Solution.cpp b/solution/3300-3399/3387.Maximize Amount After Two Days of Conversions/Solution.cpp index 3331171a888c3..bf62efc587525 100644 --- a/solution/3300-3399/3387.Maximize Amount After Two Days of Conversions/Solution.cpp +++ b/solution/3300-3399/3387.Maximize Amount After Two Days of Conversions/Solution.cpp @@ -24,7 +24,7 @@ class Solution { g[b].push_back({a, 1 / r}); } - auto dfs = [&](auto&& dfs, const string& a, double v) -> void { + auto dfs = [&](this auto&& dfs, const string& a, double v) -> void { if (d.find(a) != d.end()) { return; } @@ -32,11 +32,11 @@ class Solution { d[a] = v; for (const auto& [b, r] : g[a]) { if (d.find(b) == d.end()) { - dfs(dfs, b, v * r); + dfs(b, v * r); } } }; - dfs(dfs, init, 1.0); + dfs(init, 1.0); return d; } };