Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ea5d866

Browse files
acbinidoocs
andauthored
feat: update lc problems (doocs#2208)
Co-authored-by: Doocs Bot <doocs-bot@outlook.com>
1 parent f93b0d1 commit ea5d866

File tree

9 files changed

+25
-20
lines changed

9 files changed

+25
-20
lines changed

‎solution/2700-2799/2746.Decremental String Concatenation/README_EN.md‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,20 @@ It can be shown that the minimum possible length of str<sub>2</sub> is 6.
6868

6969
## Solutions
7070

71-
**Solution 1: Case Discussion**
71+
**Solution 1: Memoization Search**
7272

73-
We observe that the string 'AA' can only be followed by 'BB', and the string 'AB' can be placed at the beginning or end of the string. Therefore:
73+
We notice that when concatenating strings, the first and last characters of the string will affect the length of the concatenated string. Therefore, we design a function $dfs(i, a, b),ドル which represents the minimum length of the concatenated string starting from the $i$-th string, and the first character of the previously concatenated string is $a,ドル and the last character is $b$.
7474

75-
- If $x < y,ドル we can first alternately place 'BBAABBAA..BB', placing a total of $x$ 'AA' and $x+1$ 'BB', then place the remaining $z$ 'AB', with a total length of $(x \times 2 + z + 1) \times 2$;
76-
- If $x > y,ドル we can first alternately place 'AABBAABB..AA', placing a total of $y$ 'BB' and $y+1$ 'AA', then place the remaining $z$ 'AB', with a total length of $(y \times 2 + z + 1) \times 2$;
77-
- If $x = y,ドル we only need to alternately place 'AABB', placing a total of $x$ 'AA' and $y$ 'BB', then place the remaining $z$ 'AB', with a total length of $(x + y + z) \times 2$.
75+
The execution process of the function $dfs(i, a, b)$ is as follows:
7876

79-
The time complexity is $O(1),ドル and the space complexity is $O(1)$.
77+
- If $i = n,ドル it means that all strings have been concatenated, return 0ドル$;
78+
- Otherwise, we consider concatenating the $i$-th string to the end or the beginning of the already concatenated string, and get the lengths $x$ and $y$ of the concatenated string, then $dfs(i, a, b) = \min(x, y) + |words[i]|$.
79+
80+
To avoid repeated calculations, we use the method of memoization search. Specifically, we use a three-dimensional array $f$ to store all the return values of $dfs(i, a, b)$. When we need to calculate $dfs(i, a, b),ドル if $f[i][a][b]$ has been calculated, we directly return $f[i][a][b]$; otherwise, we calculate the value of $dfs(i, a, b)$ according to the above recurrence relation, and store it in $f[i][a][b]$.
81+
82+
In the main function, we directly return $|words[0]| + dfs(1, words[0][0], words[0][|words[0]| - 1])$.
83+
84+
The time complexity is $O(n \times C^2),ドル and the space complexity is $O(n \times C^2)$. Where $C$ represents the maximum length of the string.
8085

8186
<!-- tabs:start -->
8287

‎solution/3000-3099/3004.Maximum Subtree of the Same Color/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<p>Return <em>the size of such subtree with the <strong>maximum</strong> number of nodes possible.</em></p>
1616

1717
<p>&nbsp;</p>
18-
<p><strong><img alt="" src="https://assets.leetcode.com/static_assets/others/20231216-134026.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 221px; height: 132px;" /></strong></p>
18+
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/images/20231216-134026.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 221px; height: 132px;" /></strong></p>
1919

2020
<p><strong class="example">Example 1:</strong></p>
2121

@@ -33,7 +33,7 @@
3333
<strong>Explanation:</strong> The whole tree has the same color, and the subtree rooted at node 0 has the most number of nodes which is 4. Hence, we return 4.
3434
</pre>
3535

36-
<p><strong><img alt="" src="https://assets.leetcode.com/static_assets/others/20231216-134017.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 221px; height: 221px;" /></strong></p>
36+
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/images/20231216-134017.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 221px; height: 221px;" /></strong></p>
3737

3838
<p><strong class="example">Example 3:</strong></p>
3939

‎solution/3000-3099/3004.Maximum Subtree of the Same Color/README_EN.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<p>Return <em>the size of such subtree with the <strong>maximum</strong> number of nodes possible.</em></p>
1414

1515
<p>&nbsp;</p>
16-
<p><strong><img alt="" src="https://assets.leetcode.com/static_assets/others/20231216-134026.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 221px; height: 132px;" /></strong></p>
16+
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/images/20231216-134026.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 221px; height: 132px;" /></strong></p>
1717

1818
<p><strong class="example">Example 1:</strong></p>
1919

@@ -31,7 +31,7 @@
3131
<strong>Explanation:</strong> The whole tree has the same color, and the subtree rooted at node 0 has the most number of nodes which is 4. Hence, we return 4.
3232
</pre>
3333

34-
<p><strong><img alt="" src="https://assets.leetcode.com/static_assets/others/20231216-134017.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 221px; height: 221px;" /></strong></p>
34+
<p><strong><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/images/20231216-134017.png" style="padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem; width: 221px; height: 221px;" /></strong></p>
3535

3636
<p><strong class="example">Example 3:</strong></p>
3737

24 KB
Loading[フレーム]
17.7 KB
Loading[フレーム]

‎solution/DATABASE_README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@
256256
| 2989 | [班级表现](/solution/2900-2999/2989.Class%20Performance/README.md) | `数据库` | 中等 | 🔒 |
257257
| 2990 | [贷款类型](/solution/2900-2999/2990.Loan%20Types/README.md) | `数据库` | 简单 | 🔒 |
258258
| 2991 | [最好的三家酒庄](/solution/2900-2999/2991.Top%20Three%20Wineries/README.md) | `数据库` | 困难 | 🔒 |
259-
| 2993 | [Friday Purchases I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md) | `数据库` | 中等 | 🔒 |
260-
| 2994 | [Friday Purchases II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md) | `数据库` | 困难 | 🔒 |
259+
| 2993 | [发生在周五的交易 I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md) | `数据库` | 中等 | 🔒 |
260+
| 2994 | [发生在周五的交易 II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md) | `数据库` | 困难 | 🔒 |
261261
| 2995 | [观众变主播](/solution/2900-2999/2995.Viewers%20Turned%20Streamers/README.md) | `数据库` | 困难 | 🔒 |
262262

263263
## 版权

‎solution/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3003,8 +3003,8 @@
30033003
| 2990 | [贷款类型](/solution/2900-2999/2990.Loan%20Types/README.md) | `数据库` | 简单 | 🔒 |
30043004
| 2991 | [最好的三家酒庄](/solution/2900-2999/2991.Top%20Three%20Wineries/README.md) | `数据库` | 困难 | 🔒 |
30053005
| 2992 | [自整除排列的数量](/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README.md) | `位运算`,`递归`,`数组`,`动态规划`,`状态压缩` | 中等 | 🔒 |
3006-
| 2993 | [Friday Purchases I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md) | `数据库` | 中等 | 🔒 |
3007-
| 2994 | [Friday Purchases II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md) | `数据库` | 困难 | 🔒 |
3006+
| 2993 | [发生在周五的交易 I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md) | `数据库` | 中等 | 🔒 |
3007+
| 2994 | [发生在周五的交易 II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md) | `数据库` | 困难 | 🔒 |
30083008
| 2995 | [观众变主播](/solution/2900-2999/2995.Viewers%20Turned%20Streamers/README.md) | `数据库` | 困难 | 🔒 |
30093009
| 2996 | [大于等于顺序前缀和的最小缺失整数](/solution/2900-2999/2996.Smallest%20Missing%20Integer%20Greater%20Than%20Sequential%20Prefix%20Sum/README.md) | `数组`,`哈希表`,`排序` | 简单 | 第 121 场双周赛 |
30103010
| 2997 | [使数组异或和等于 K 的最少操作次数](/solution/2900-2999/2997.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20XOR%20Equal%20to%20K/README.md) | `位运算`,`数组` | 中等 | 第 121 场双周赛 |
@@ -3014,7 +3014,7 @@
30143014
| 3001 | [捕获黑皇后需要的最少移动次数](/solution/3000-3099/3001.Minimum%20Moves%20to%20Capture%20The%20Queen/README.md) | `数组`,`枚举` | 中等 | 第 379 场周赛 |
30153015
| 3002 | [移除后集合的最多元素数](/solution/3000-3099/3002.Maximum%20Size%20of%20a%20Set%20After%20Removals/README.md) | `贪心`,`数组`,`哈希表` | 中等 | 第 379 场周赛 |
30163016
| 3003 | [执行操作后的最大分割数量](/solution/3000-3099/3003.Maximize%20the%20Number%20of%20Partitions%20After%20Operations/README.md) | `位运算`,`字符串`,`动态规划`,`状态压缩` | 困难 | 第 379 场周赛 |
3017-
| 3004 | [Maximum Subtree of the Same Color](/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/README.md) | | 中等 | 🔒 |
3017+
| 3004 | [相同颜色的最大子树](/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/README.md) | | 中等 | 🔒 |
30183018

30193019
## 版权
30203020

‎solution/database-summary.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,6 @@
246246
- [2989.班级表现](/database-solution/2900-2999/2989.Class%20Performance/README.md)
247247
- [2990.贷款类型](/database-solution/2900-2999/2990.Loan%20Types/README.md)
248248
- [2991.最好的三家酒庄](/database-solution/2900-2999/2991.Top%20Three%20Wineries/README.md)
249-
- [2993.Friday Purchases I](/database-solution/2900-2999/2993.Friday%20Purchases%20I/README.md)
250-
- [2994.Friday Purchases II](/database-solution/2900-2999/2994.Friday%20Purchases%20II/README.md)
249+
- [2993.发生在周五的交易 I](/database-solution/2900-2999/2993.Friday%20Purchases%20I/README.md)
250+
- [2994.发生在周五的交易 II](/database-solution/2900-2999/2994.Friday%20Purchases%20II/README.md)
251251
- [2995.观众变主播](/database-solution/2900-2999/2995.Viewers%20Turned%20Streamers/README.md)

‎solution/summary.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3050,8 +3050,8 @@
30503050
- [2990.贷款类型](/solution/2900-2999/2990.Loan%20Types/README.md)
30513051
- [2991.最好的三家酒庄](/solution/2900-2999/2991.Top%20Three%20Wineries/README.md)
30523052
- [2992.自整除排列的数量](/solution/2900-2999/2992.Number%20of%20Self-Divisible%20Permutations/README.md)
3053-
- [2993.Friday Purchases I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md)
3054-
- [2994.Friday Purchases II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md)
3053+
- [2993.发生在周五的交易 I](/solution/2900-2999/2993.Friday%20Purchases%20I/README.md)
3054+
- [2994.发生在周五的交易 II](/solution/2900-2999/2994.Friday%20Purchases%20II/README.md)
30553055
- [2995.观众变主播](/solution/2900-2999/2995.Viewers%20Turned%20Streamers/README.md)
30563056
- [2996.大于等于顺序前缀和的最小缺失整数](/solution/2900-2999/2996.Smallest%20Missing%20Integer%20Greater%20Than%20Sequential%20Prefix%20Sum/README.md)
30573057
- [2997.使数组异或和等于 K 的最少操作次数](/solution/2900-2999/2997.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20XOR%20Equal%20to%20K/README.md)
@@ -3063,4 +3063,4 @@
30633063
- [3001.捕获黑皇后需要的最少移动次数](/solution/3000-3099/3001.Minimum%20Moves%20to%20Capture%20The%20Queen/README.md)
30643064
- [3002.移除后集合的最多元素数](/solution/3000-3099/3002.Maximum%20Size%20of%20a%20Set%20After%20Removals/README.md)
30653065
- [3003.执行操作后的最大分割数量](/solution/3000-3099/3003.Maximize%20the%20Number%20of%20Partitions%20After%20Operations/README.md)
3066-
- [3004.Maximum Subtree of the Same Color](/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/README.md)
3066+
- [3004.相同颜色的最大子树](/solution/3000-3099/3004.Maximum%20Subtree%20of%20the%20Same%20Color/README.md)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /