From 6b8f5fa1a6d1ed8006314b171d1696668044c7d4 Mon Sep 17 00:00:00 2001 From: acbin <44314231+acbin@users.noreply.github.com> Date: Thu, 7 Dec 2023 04:56:43 +0000 Subject: [PATCH 1/2] feat: add new lc problem --- .../README.md | 90 +++++++++++++++++++ .../README_EN.md | 82 +++++++++++++++++ solution/README.md | 1 + solution/README_EN.md | 1 + solution/main.py | 9 +- solution/summary.md | 1 + solution/summary_en.md | 1 + 7 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 solution/2900-2999/2955.Number of Same-End Substrings/README.md create mode 100644 solution/2900-2999/2955.Number of Same-End Substrings/README_EN.md diff --git a/solution/2900-2999/2955.Number of Same-End Substrings/README.md b/solution/2900-2999/2955.Number of Same-End Substrings/README.md new file mode 100644 index 0000000000000..7323583b26ab6 --- /dev/null +++ b/solution/2900-2999/2955.Number of Same-End Substrings/README.md @@ -0,0 +1,90 @@ +# [2955. Number of Same-End Substrings](https://leetcode.cn/problems/number-of-same-end-substrings) + +[English Version](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README_EN.md) + +## 题目描述 + + + +

You are given a 0-indexed string s, and a 2D array of integers queries, where queries[i] = [li, ri] indicates a substring of s starting from the index li and ending at the index ri (both inclusive), i.e. s[li..ri].

+ +

Return an array ans where ans[i] is the number of same-end substrings of queries[i].

+ +

A 0-indexed string t of length n is called same-end if it has the same character at both of its ends, i.e., t[0] == t[n - 1].

+ +

A substring is a contiguous non-empty sequence of characters within a string.

+ +

 

+

Example 1:

+ +
+Input: s = "abcaab", queries = [[0,0],[1,4],[2,5],[0,5]]
+Output: [1,5,5,10]
+Explanation: Here is the same-end substrings of each query:
+1st query: s[0..0] is "a" which has 1 same-end substring: "a".
+2nd query: s[1..4] is "bcaa" which has 5 same-end substrings: "bcaa", "bcaa", "bcaa", "bcaa", "bcaa".
+3rd query: s[2..5] is "caab" which has 5 same-end substrings: "caab", "caab", "caab", "caab", "caab".
+4th query: s[0..5] is "abcaab" which has 10 same-end substrings: "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab".
+
+ +

Example 2:

+ +
+Input: s = "abcd", queries = [[0,3]]
+Output: [4]
+Explanation: The only query is s[0..3] which is "abcd". It has 4 same-end substrings: "abcd", "abcd", "abcd", "abcd".
+
+ +

 

+

Constraints:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2955.Number of Same-End Substrings/README_EN.md b/solution/2900-2999/2955.Number of Same-End Substrings/README_EN.md new file mode 100644 index 0000000000000..814c19816557d --- /dev/null +++ b/solution/2900-2999/2955.Number of Same-End Substrings/README_EN.md @@ -0,0 +1,82 @@ +# [2955. Number of Same-End Substrings](https://leetcode.com/problems/number-of-same-end-substrings) + +[中文文档](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README.md) + +## Description + +

You are given a 0-indexed string s, and a 2D array of integers queries, where queries[i] = [li, ri] indicates a substring of s starting from the index li and ending at the index ri (both inclusive), i.e. s[li..ri].

+ +

Return an array ans where ans[i] is the number of same-end substrings of queries[i].

+ +

A 0-indexed string t of length n is called same-end if it has the same character at both of its ends, i.e., t[0] == t[n - 1].

+ +

A substring is a contiguous non-empty sequence of characters within a string.

+ +

 

+

Example 1:

+ +
+Input: s = "abcaab", queries = [[0,0],[1,4],[2,5],[0,5]]
+Output: [1,5,5,10]
+Explanation: Here is the same-end substrings of each query:
+1st query: s[0..0] is "a" which has 1 same-end substring: "a".
+2nd query: s[1..4] is "bcaa" which has 5 same-end substrings: "bcaa", "bcaa", "bcaa", "bcaa", "bcaa".
+3rd query: s[2..5] is "caab" which has 5 same-end substrings: "caab", "caab", "caab", "caab", "caab".
+4th query: s[0..5] is "abcaab" which has 10 same-end substrings: "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab", "abcaab".
+
+ +

Example 2:

+ +
+Input: s = "abcd", queries = [[0,3]]
+Output: [4]
+Explanation: The only query is s[0..3] which is "abcd". It has 4 same-end substrings: "abcd", "abcd", "abcd", "abcd".
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/README.md b/solution/README.md index 2d55f769b02a9..170115cedf76b 100644 --- a/solution/README.md +++ b/solution/README.md @@ -2965,6 +2965,7 @@ | 2952 | [需要添加的硬币的最小数量](/solution/2900-2999/2952.Minimum%20Number%20of%20Coins%20to%20be%20Added/README.md) | | 中等 | 第 374 场周赛 | | 2953 | [统计完全子字符串](/solution/2900-2999/2953.Count%20Complete%20Substrings/README.md) | | 中等 | 第 374 场周赛 | | 2954 | [统计感冒序列的数目](/solution/2900-2999/2954.Count%20the%20Number%20of%20Infection%20Sequences/README.md) | | 困难 | 第 374 场周赛 | +| 2955 | [Number of Same-End Substrings](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README.md) | | 中等 | 🔒 | ## 版权 diff --git a/solution/README_EN.md b/solution/README_EN.md index 0ba480b7f4932..af307782fa5fe 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -2963,6 +2963,7 @@ Press Control + F(or Command + F on | 2952 | [Minimum Number of Coins to be Added](/solution/2900-2999/2952.Minimum%20Number%20of%20Coins%20to%20be%20Added/README_EN.md) | | Medium | Weekly Contest 374 | | 2953 | [Count Complete Substrings](/solution/2900-2999/2953.Count%20Complete%20Substrings/README_EN.md) | | Medium | Weekly Contest 374 | | 2954 | [Count the Number of Infection Sequences](/solution/2900-2999/2954.Count%20the%20Number%20of%20Infection%20Sequences/README_EN.md) | | Hard | Weekly Contest 374 | +| 2955 | [Number of Same-End Substrings](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README_EN.md) | | Medium | 🔒 | ## Copyright diff --git a/solution/main.py b/solution/main.py index 621c50b3d9db4..21b6f2f4952cd 100644 --- a/solution/main.py +++ b/solution/main.py @@ -50,7 +50,7 @@ def get_all_questions(self, retry: int = 3) -> List: ) return resp.json()["stat_status_pairs"] except Exception as e: - print(e) + print('get_all_questions', e) time.sleep(2) return self.get_all_questions(retry - 1) if retry > 0 else [] @@ -100,12 +100,15 @@ def get_question_detail_en(self, question_title_slug: str, retry: int = 3) -> di res = resp.json() return res["data"]["question"] or {} except Exception as e: - print(e) + print('get_question_detail_en', e) + if 'is not defined' in str(e): + return {} time.sleep(2) return {} def get_question_detail(self, question_title_slug: str, retry: int = 3) -> dict: """获取题目详情""" + print(question_title_slug) form1 = { "operationName": "globalData", "query": "query globalData {\n feature {\n questionTranslation\n subscription\n signUp\n " @@ -170,7 +173,7 @@ def get_question_detail(self, question_title_slug: str, retry: int = 3) -> dict: res = resp.json() return res["data"]["question"] or {} except Exception as e: - print(e) + print('get_question_detail', e) time.sleep(2) return {} diff --git a/solution/summary.md b/solution/summary.md index 8e339248115bf..48cb7b7b590cd 100644 --- a/solution/summary.md +++ b/solution/summary.md @@ -3012,3 +3012,4 @@ - [2952.需要添加的硬币的最小数量](/solution/2900-2999/2952.Minimum%20Number%20of%20Coins%20to%20be%20Added/README.md) - [2953.统计完全子字符串](/solution/2900-2999/2953.Count%20Complete%20Substrings/README.md) - [2954.统计感冒序列的数目](/solution/2900-2999/2954.Count%20the%20Number%20of%20Infection%20Sequences/README.md) + - [2955.Number of Same-End Substrings](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README.md) diff --git a/solution/summary_en.md b/solution/summary_en.md index 5efd1139a28de..3fac05358fb0b 100644 --- a/solution/summary_en.md +++ b/solution/summary_en.md @@ -3012,3 +3012,4 @@ - [2952.Minimum Number of Coins to be Added](/solution/2900-2999/2952.Minimum%20Number%20of%20Coins%20to%20be%20Added/README_EN.md) - [2953.Count Complete Substrings](/solution/2900-2999/2953.Count%20Complete%20Substrings/README_EN.md) - [2954.Count the Number of Infection Sequences](/solution/2900-2999/2954.Count%20the%20Number%20of%20Infection%20Sequences/README_EN.md) + - [2955.Number of Same-End Substrings](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README_EN.md) From 35120d381a3f57b44e78988724d7d9671f5fc7e3 Mon Sep 17 00:00:00 2001 From: acbin <44314231+acbin@users.noreply.github.com> Date: Thu, 7 Dec 2023 06:31:28 +0000 Subject: [PATCH 2/2] docs: update --- .../README.md | 4 +- .../README_EN.md | 17 +++++--- .../1084.Sales Analysis III/README.md | 8 ++-- .../1522.Diameter of N-Ary Tree/README.md | 2 +- .../1522.Diameter of N-Ary Tree/README_EN.md | 2 +- .../README.md | 4 +- .../README.md | 2 +- .../README.md | 2 +- .../2715.Timeout Cancellation/README_EN.md | 41 ++++++++++++------- .../README.md | 2 +- solution/README.md | 16 ++++---- solution/README_EN.md | 16 ++++---- solution/main.py | 1 - 13 files changed, 68 insertions(+), 49 deletions(-) diff --git a/solution/0500-0599/0557.Reverse Words in a String III/README.md b/solution/0500-0599/0557.Reverse Words in a String III/README.md index 87ad806d27284..db4cce4b64360 100644 --- a/solution/0500-0599/0557.Reverse Words in a String III/README.md +++ b/solution/0500-0599/0557.Reverse Words in a String III/README.md @@ -20,8 +20,8 @@

示例 2:

-输入: s = "God Ding"
-输出:"doG gniD"
+输入: s = "Mr Ding"
+输出:"rM gniD"
 

 

diff --git a/solution/0500-0599/0557.Reverse Words in a String III/README_EN.md b/solution/0500-0599/0557.Reverse Words in a String III/README_EN.md index 083b24bcee914..01a01dea23681 100644 --- a/solution/0500-0599/0557.Reverse Words in a String III/README_EN.md +++ b/solution/0500-0599/0557.Reverse Words in a String III/README_EN.md @@ -8,12 +8,19 @@

 

Example 1:

-
Input: s = "Let's take LeetCode contest"
-Output: "s'teL ekat edoCteeL tsetnoc"
-

Example 2:

-
Input: s = "God Ding"
-Output: "doG gniD"
+
+
+Input: s = "Let's take LeetCode contest"
+Output: "s'teL ekat edoCteeL tsetnoc"
 
+ +

Example 2:

+ +
+Input: s = "Mr Ding"
+Output: "rM gniD"
+
+

 

Constraints:

diff --git a/solution/1000-1099/1084.Sales Analysis III/README.md b/solution/1000-1099/1084.Sales Analysis III/README.md index 44a00d317897a..60e1b4b611408 100644 --- a/solution/1000-1099/1084.Sales Analysis III/README.md +++ b/solution/1000-1099/1084.Sales Analysis III/README.md @@ -76,10 +76,10 @@ Product table: | 1 | S8 | +-------------+--------------+ 解释: -id为1的产品仅在2019年春季销售。 -id为2的产品在2019年春季销售,但也在2019年春季之后销售。 -id 3的产品在2019年春季之后销售。 -我们只退回产品1,因为它是2019年春季才销售的产品。
+id 为 1 的产品仅在 2019 年春季销售。 +id 为 2 的产品在 2019 年春季销售,但也在 2019 年春季之后销售。 +id 为 3 的产品在 2019 年春季之后销售。 +我们只返回 id 为 1 的产品,因为它是 2019 年春季才销售的产品。 ## 解法 diff --git a/solution/1500-1599/1522.Diameter of N-Ary Tree/README.md b/solution/1500-1599/1522.Diameter of N-Ary Tree/README.md index f869b4d797281..05088054ef6c8 100644 --- a/solution/1500-1599/1522.Diameter of N-Ary Tree/README.md +++ b/solution/1500-1599/1522.Diameter of N-Ary Tree/README.md @@ -6,7 +6,7 @@ -

给定一棵 N 叉树的根节点 root ,计算这棵树的直径长度。

+

给定一棵 N 叉树 的根节点 root ,计算这棵树的直径长度。

N 叉树的直径指的是树中任意两个节点间路径中 最长 路径的长度。这条路径可能经过根节点,也可能不经过根节点。

diff --git a/solution/1500-1599/1522.Diameter of N-Ary Tree/README_EN.md b/solution/1500-1599/1522.Diameter of N-Ary Tree/README_EN.md index 6b746b622b8ab..bb3a3891de2bb 100644 --- a/solution/1500-1599/1522.Diameter of N-Ary Tree/README_EN.md +++ b/solution/1500-1599/1522.Diameter of N-Ary Tree/README_EN.md @@ -4,7 +4,7 @@ ## Description -

Given a root of an N-ary tree, you need to compute the length of the diameter of the tree.

+

Given a root of an N-ary tree, you need to compute the length of the diameter of the tree.

The diameter of an N-ary tree is the length of the longest path between any two nodes in the tree. This path may or may not pass through the root.

diff --git a/solution/2400-2499/2431.Maximize Total Tastiness of Purchased Fruits/README.md b/solution/2400-2499/2431.Maximize Total Tastiness of Purchased Fruits/README.md index 45f11370eb289..dd83245c179e0 100644 --- a/solution/2400-2499/2431.Maximize Total Tastiness of Purchased Fruits/README.md +++ b/solution/2400-2499/2431.Maximize Total Tastiness of Purchased Fruits/README.md @@ -26,8 +26,8 @@

注意:

 

diff --git a/solution/2400-2499/2436.Minimum Split Into Subarrays With GCD Greater Than One/README.md b/solution/2400-2499/2436.Minimum Split Into Subarrays With GCD Greater Than One/README.md index 17069dd0e7936..692421f2285a6 100644 --- a/solution/2400-2499/2436.Minimum Split Into Subarrays With GCD Greater Than One/README.md +++ b/solution/2400-2499/2436.Minimum Split Into Subarrays With GCD Greater Than One/README.md @@ -8,7 +8,7 @@

给定一个由正整数组成的数组 nums

-

将数组拆分为 一个或多个 不相连的子数组,如下所示:

+

将数组拆分为 一个或多个 互相不覆盖的子数组,如下所示: