diff --git a/solution/3300-3399/3355.Zero Array Transformation I/README.md b/solution/3300-3399/3355.Zero Array Transformation I/README.md
index f480e91a5527e..77d4c74f29890 100644
--- a/solution/3300-3399/3355.Zero Array Transformation I/README.md
+++ b/solution/3300-3399/3355.Zero Array Transformation I/README.md
@@ -22,7 +22,7 @@ tags:
对于每个查询 queries[i]
:
- - 在
nums
的下标范围 [li, ri]
内选择一个下标子集。
+ - 在
nums
的下标范围 [li, ri]
内选择一个下标 子集。
- 将选中的每个下标对应的元素值减 1。
@@ -30,8 +30,6 @@ tags:
如果在按顺序处理所有查询后,可以将 nums
转换为 零数组 ,则返回 true
,否则返回 false
。
-数组的 子集 是对数组元素的选择(可能为空)。
-
示例 1:
diff --git a/solution/3300-3399/3359.Find Sorted Submatrices With Maximum Element at Most K/README.md b/solution/3300-3399/3359.Find Sorted Submatrices With Maximum Element at Most K/README.md
index bd3e5fd2aca1d..2c3f09746e977 100644
--- a/solution/3300-3399/3359.Find Sorted Submatrices With Maximum Element at Most K/README.md
+++ b/solution/3300-3399/3359.Find Sorted Submatrices With Maximum Element at Most K/README.md
@@ -6,7 +6,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3359.Fi
-# [3359. Find Sorted Submatrices With Maximum Element at Most K 🔒](https://leetcode.cn/problems/find-sorted-submatrices-with-maximum-element-at-most-k)
+# [3359. 查找最大元素不超过 K 的有序子矩阵 🔒](https://leetcode.cn/problems/find-sorted-submatrices-with-maximum-element-at-most-k)
[English Version](/solution/3300-3399/3359.Find%20Sorted%20Submatrices%20With%20Maximum%20Element%20at%20Most%20K/README_EN.md)
@@ -14,30 +14,31 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3359.Fi
-You are given a 2D matrix grid
of size m x n
. You are also given a non-negative integer k
.
+给定一个大小为 m x n
的二维矩阵 grid
。同时给定一个 非负整数 k
。
-Return the number of submatrices of grid
that satisfy the following conditions:
+返回满足下列条件的 grid
的子矩阵:
- - The maximum element in the submatrix less than or equal to
k
.
- - Each row in the submatrix is sorted in non-increasing order.
+ - 子矩阵中最大的元素 小于等于
k
。
+ - 子矩阵的每一行都以 非递增 顺序排序。
-A submatrix (x1, y1, x2, y2)
is a matrix that forms by choosing all cells grid[x][y]
where x1 <= x <= x2
and y1 <= y <= y2
.
+矩阵的子矩阵 (x1, y1, x2, y2)
是通过选择所有满足 x1 <= x <= x2
且 y1 <= y <= y2
的 grid[x][y]
元素组成的矩阵。
-Example 1:
+
+示例 1:
-
Input: grid = [[4,3,2,1],[8,7,6,1]], k = 3
+
输入:grid = [[4,3,2,1],[8,7,6,1]], k = 3
-
Output: 8
+
输出:8
-
Explanation:
+
解释:

-
The 8 submatrices are:
+
8 个子矩阵分别是:
[[1]]
@@ -51,28 +52,29 @@ edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3359.Fi
-Example 2:
+示例 2:
-
Input: grid = [[1,1,1],[1,1,1],[1,1,1]], k = 1
+
输入:grid = [[1,1,1],[1,1,1],[1,1,1]], k = 1
-
Output: 36
+
输出:36
-
Explanation:
+
解释:
-
There are 36 submatrices of grid. All submatrices have their maximum element equal to 1.
+
矩阵中有 36 个子矩阵。所有子矩阵的最大元素都等于 1。
-Example 3:
+示例 3:
-
Input: grid = [[1]], k = 1
+
输入:grid = [[1]], k = 1
-
Output: 1
+
输出:1
-Constraints:
+
+提示:
1 <= m == grid.length <= 103
diff --git a/solution/3300-3399/3368.First Letter Capitalization/README.md b/solution/3300-3399/3368.First Letter Capitalization/README.md
index 2c4e97c5d1f72..90ae5b8f17cb7 100644
--- a/solution/3300-3399/3368.First Letter Capitalization/README.md
+++ b/solution/3300-3399/3368.First Letter Capitalization/README.md
@@ -8,7 +8,7 @@ tags:
-# [3368. First Letter Capitalization 🔒](https://leetcode.cn/problems/first-letter-capitalization)
+# [3368. 首字母大写 🔒](https://leetcode.cn/problems/first-letter-capitalization)
[English Version](/solution/3300-3399/3368.First%20Letter%20Capitalization/README_EN.md)
@@ -16,7 +16,7 @@ tags:
-Table: user_content
+表:user_content
+-------------+---------+
@@ -25,31 +25,32 @@ tags:
| content_id | int |
| content_text| varchar |
+-------------+---------+
-content_id is the unique key for this table.
-Each row contains a unique ID and the corresponding text content.
+content_id 是这张表的唯一主键。
+每一行包含一个不同的 ID 以及对应的文本内容。
-Write a solution to transform the text in the content_text
column by applying the following rules:
+编写一个解决方案来通过应用以下规则来转换 content_text
列中的文本:
- - Convert the first letter of each word to uppercase
- - Keep all other letters in lowercase
- - Preserve all existing spaces
+ - 把每个单词的首字母变成大写
+ - 其它字母保持小写
+ - 保留所有现有空格
-Note: There will be no special character in content_text
.
+注意:content_text
中没有特殊字符。
-Return the result table that includes both the original content_text
and the modified text where each word starts with a capital letter.
+返回结果表,同时包含原来的 content_text
以及将所有单词首字母变成大写的修改后文本。
-The result format is in the following example.
+结果格式如下所示。
-Example:
+
+示例:
-
Input:
+
输入:
-
user_content table:
+
user_content 表:
+------------+-----------------------------------+
@@ -62,7 +63,7 @@ Each row contains a unique ID and the corresponding text content.
+------------+-----------------------------------+
-
Output:
+
输出:
+------------+-----------------------------------+-----------------------------------+
@@ -75,28 +76,28 @@ Each row contains a unique ID and the corresponding text content.
+------------+-----------------------------------+-----------------------------------+
-
Explanation:
+
解释:
- - For content_id = 1:
+
- 对于 content_id = 1:
- - Each word's first letter is capitalized: Hello World Of SQL
+ - 每个单词的首字母都已经大写:Hello World Of SQL
- - For content_id = 2:
+
- 对于 content_id = 2:
- - Original mixed-case text is transformed to title case: The Quick Brown Fox
+ - 原来混合大小写的文本变为首字母大写:The Quick Brown Fox
- - For content_id = 3:
+
- 对于 content_id = 3:
- - The word AND is converted to "And": "Data Science And Machine Learning"
+ - 单词 AND 被转换为 "And":"Data Science And Machine Learning"
- - For content_id = 4:
+
- 对于 content_id = 4:
- - Handles word TOP rated correctly: Top Rated
- - Converts BOOKS from all caps to title case: Books
+ - 正确处理单词 TOP rated:Top Rated
+ - 将 BOOKS 从全大写改为首字母大写:Books
@@ -115,7 +116,59 @@ Each row contains a unique ID and the corresponding text content.
#### MySQL
```sql
+WITH RECURSIVE
+ capitalized_words AS (
+ SELECT
+ content_id,
+ content_text,
+ SUBSTRING_INDEX(content_text, ' ', 1) AS word,
+ SUBSTRING(
+ content_text,
+ LENGTH(SUBSTRING_INDEX(content_text, ' ', 1)) + 2
+ ) AS remaining_text,
+ CONCAT(
+ UPPER(LEFT(SUBSTRING_INDEX(content_text, ' ', 1), 1)),
+ LOWER(SUBSTRING(SUBSTRING_INDEX(content_text, ' ', 1), 2))
+ ) AS processed_word
+ FROM user_content
+ UNION ALL
+ SELECT
+ c.content_id,
+ c.content_text,
+ SUBSTRING_INDEX(c.remaining_text, ' ', 1),
+ SUBSTRING(c.remaining_text, LENGTH(SUBSTRING_INDEX(c.remaining_text, ' ', 1)) + 2),
+ CONCAT(
+ c.processed_word,
+ ' ',
+ CONCAT(
+ UPPER(LEFT(SUBSTRING_INDEX(c.remaining_text, ' ', 1), 1)),
+ LOWER(SUBSTRING(SUBSTRING_INDEX(c.remaining_text, ' ', 1), 2))
+ )
+ )
+ FROM capitalized_words c
+ WHERE c.remaining_text != ''
+ )
+SELECT
+ content_id,
+ content_text AS original_text,
+ MAX(processed_word) AS converted_text
+FROM capitalized_words
+GROUP BY 1, 2;
+```
+
+#### Pandas
+
+```python
+import pandas as pd
+
+def process_text(user_content: pd.DataFrame) -> pd.DataFrame:
+ user_content["converted_text"] = user_content["content_text"].apply(
+ lambda text: " ".join(word.capitalize() for word in text.split(" "))
+ )
+ return user_content[["content_id", "content_text", "converted_text"]].rename(
+ columns={"content_text": "original_text"}
+ )
```
diff --git a/solution/3300-3399/3368.First Letter Capitalization/README_EN.md b/solution/3300-3399/3368.First Letter Capitalization/README_EN.md
index 3f7e3b8c3c81a..580c863e357e2 100644
--- a/solution/3300-3399/3368.First Letter Capitalization/README_EN.md
+++ b/solution/3300-3399/3368.First Letter Capitalization/README_EN.md
@@ -115,7 +115,59 @@ Each row contains a unique ID and the corresponding text content.
#### MySQL
```sql
+WITH RECURSIVE
+ capitalized_words AS (
+ SELECT
+ content_id,
+ content_text,
+ SUBSTRING_INDEX(content_text, ' ', 1) AS word,
+ SUBSTRING(
+ content_text,
+ LENGTH(SUBSTRING_INDEX(content_text, ' ', 1)) + 2
+ ) AS remaining_text,
+ CONCAT(
+ UPPER(LEFT(SUBSTRING_INDEX(content_text, ' ', 1), 1)),
+ LOWER(SUBSTRING(SUBSTRING_INDEX(content_text, ' ', 1), 2))
+ ) AS processed_word
+ FROM user_content
+ UNION ALL
+ SELECT
+ c.content_id,
+ c.content_text,
+ SUBSTRING_INDEX(c.remaining_text, ' ', 1),
+ SUBSTRING(c.remaining_text, LENGTH(SUBSTRING_INDEX(c.remaining_text, ' ', 1)) + 2),
+ CONCAT(
+ c.processed_word,
+ ' ',
+ CONCAT(
+ UPPER(LEFT(SUBSTRING_INDEX(c.remaining_text, ' ', 1), 1)),
+ LOWER(SUBSTRING(SUBSTRING_INDEX(c.remaining_text, ' ', 1), 2))
+ )
+ )
+ FROM capitalized_words c
+ WHERE c.remaining_text != ''
+ )
+SELECT
+ content_id,
+ content_text AS original_text,
+ MAX(processed_word) AS converted_text
+FROM capitalized_words
+GROUP BY 1, 2;
+```
+
+#### Pandas
+
+```python
+import pandas as pd
+
+def process_text(user_content: pd.DataFrame) -> pd.DataFrame:
+ user_content["converted_text"] = user_content["content_text"].apply(
+ lambda text: " ".join(word.capitalize() for word in text.split(" "))
+ )
+ return user_content[["content_id", "content_text", "converted_text"]].rename(
+ columns={"content_text": "original_text"}
+ )
```
diff --git a/solution/3300-3399/3368.First Letter Capitalization/Solution.py b/solution/3300-3399/3368.First Letter Capitalization/Solution.py
new file mode 100644
index 0000000000000..f00b6ccb4774b
--- /dev/null
+++ b/solution/3300-3399/3368.First Letter Capitalization/Solution.py
@@ -0,0 +1,10 @@
+import pandas as pd
+
+
+def process_text(user_content: pd.DataFrame) -> pd.DataFrame:
+ user_content["converted_text"] = user_content["content_text"].apply(
+ lambda text: " ".join(word.capitalize() for word in text.split(" "))
+ )
+ return user_content[["content_id", "content_text", "converted_text"]].rename(
+ columns={"content_text": "original_text"}
+ )
diff --git a/solution/3300-3399/3368.First Letter Capitalization/Solution.sql b/solution/3300-3399/3368.First Letter Capitalization/Solution.sql
new file mode 100644
index 0000000000000..29cea3efbdd94
--- /dev/null
+++ b/solution/3300-3399/3368.First Letter Capitalization/Solution.sql
@@ -0,0 +1,38 @@
+WITH RECURSIVE
+ capitalized_words AS (
+ SELECT
+ content_id,
+ content_text,
+ SUBSTRING_INDEX(content_text, ' ', 1) AS word,
+ SUBSTRING(
+ content_text,
+ LENGTH(SUBSTRING_INDEX(content_text, ' ', 1)) + 2
+ ) AS remaining_text,
+ CONCAT(
+ UPPER(LEFT(SUBSTRING_INDEX(content_text, ' ', 1), 1)),
+ LOWER(SUBSTRING(SUBSTRING_INDEX(content_text, ' ', 1), 2))
+ ) AS processed_word
+ FROM user_content
+ UNION ALL
+ SELECT
+ c.content_id,
+ c.content_text,
+ SUBSTRING_INDEX(c.remaining_text, ' ', 1),
+ SUBSTRING(c.remaining_text, LENGTH(SUBSTRING_INDEX(c.remaining_text, ' ', 1)) + 2),
+ CONCAT(
+ c.processed_word,
+ ' ',
+ CONCAT(
+ UPPER(LEFT(SUBSTRING_INDEX(c.remaining_text, ' ', 1), 1)),
+ LOWER(SUBSTRING(SUBSTRING_INDEX(c.remaining_text, ' ', 1), 2))
+ )
+ )
+ FROM capitalized_words c
+ WHERE c.remaining_text != ''
+ )
+SELECT
+ content_id,
+ content_text AS original_text,
+ MAX(processed_word) AS converted_text
+FROM capitalized_words
+GROUP BY 1, 2;
diff --git a/solution/DATABASE_README.md b/solution/DATABASE_README.md
index 1aa3487ed96ce..3200ddda0ecbe 100644
--- a/solution/DATABASE_README.md
+++ b/solution/DATABASE_README.md
@@ -301,7 +301,7 @@
| 3328 | [查找每个州的城市 II](/solution/3300-3399/3328.Find%20Cities%20in%20Each%20State%20II/README.md) | `数据库` | 中等 | 🔒 |
| 3338 | [第二高的薪水 II](/solution/3300-3399/3338.Second%20Highest%20Salary%20II/README.md) | `数据库` | 中等 | 🔒 |
| 3358 | [评分为 NULL 的图书](/solution/3300-3399/3358.Books%20with%20NULL%20Ratings/README.md) | `数据库` | 简单 | 🔒 |
-| 3368 | [First Letter Capitalization](/solution/3300-3399/3368.First%20Letter%20Capitalization/README.md) | | 困难 | 🔒 |
+| 3368 | [首字母大写](/solution/3300-3399/3368.First%20Letter%20Capitalization/README.md) | | 困难 | 🔒 |
## 版权
diff --git a/solution/README.md b/solution/README.md
index 23e670b4789c8..5e68a609193df 100644
--- a/solution/README.md
+++ b/solution/README.md
@@ -3369,7 +3369,7 @@
| 3356 | [零数组变换 II](/solution/3300-3399/3356.Zero%20Array%20Transformation%20II/README.md) | `数组`,`二分查找`,`前缀和` | 中等 | 第 424 场周赛 |
| 3357 | [最小化相邻元素的最大差值](/solution/3300-3399/3357.Minimize%20the%20Maximum%20Adjacent%20Element%20Difference/README.md) | `贪心`,`数组`,`二分查找` | 困难 | 第 424 场周赛 |
| 3358 | [评分为 NULL 的图书](/solution/3300-3399/3358.Books%20with%20NULL%20Ratings/README.md) | `数据库` | 简单 | 🔒 |
-| 3359 | [Find Sorted Submatrices With Maximum Element at Most K](/solution/3300-3399/3359.Find%20Sorted%20Submatrices%20With%20Maximum%20Element%20at%20Most%20K/README.md) | | 困难 | 🔒 |
+| 3359 | [查找最大元素不超过 K 的有序子矩阵](/solution/3300-3399/3359.Find%20Sorted%20Submatrices%20With%20Maximum%20Element%20at%20Most%20K/README.md) | | 困难 | 🔒 |
| 3360 | [移除石头游戏](/solution/3300-3399/3360.Stone%20Removal%20Game/README.md) | | 简单 | 第 144 场双周赛 |
| 3361 | [两个字符串的切换距离](/solution/3300-3399/3361.Shift%20Distance%20Between%20Two%20Strings/README.md) | | 中等 | 第 144 场双周赛 |
| 3362 | [零数组变换 III](/solution/3300-3399/3362.Zero%20Array%20Transformation%20III/README.md) | | 中等 | 第 144 场双周赛 |
@@ -3378,7 +3378,7 @@
| 3365 | [重排子字符串以形成目标字符串](/solution/3300-3399/3365.Rearrange%20K%20Substrings%20to%20Form%20Target%20String/README.md) | | 中等 | 第 425 场周赛 |
| 3366 | [最小数组和](/solution/3300-3399/3366.Minimum%20Array%20Sum/README.md) | | 中等 | 第 425 场周赛 |
| 3367 | [移除边之后的权重最大和](/solution/3300-3399/3367.Maximize%20Sum%20of%20Weights%20after%20Edge%20Removals/README.md) | | 困难 | 第 425 场周赛 |
-| 3368 | [First Letter Capitalization](/solution/3300-3399/3368.First%20Letter%20Capitalization/README.md) | | 困难 | 🔒 |
+| 3368 | [首字母大写](/solution/3300-3399/3368.First%20Letter%20Capitalization/README.md) | | 困难 | 🔒 |
## 版权