From bfecda9fc075301d18cfcd2906375522e7da26aa Mon Sep 17 00:00:00 2001 From: acbin <44314231+acbin@users.noreply.github.com> Date: Sun, 24 Dec 2023 08:44:22 +0000 Subject: [PATCH 1/2] feat: add weekly contest 377 --- .../README.md | 4 +- .../README_EN.md | 4 +- .../README.md | 4 +- .../README_EN.md | 4 +- .../README.md | 4 +- .../README_EN.md | 4 +- .../README.md | 10 +- .../README_EN.md | 10 +- .../images/screenshot-2023-11-10-012513.png | Bin .../images/screenshot-2023-11-10-012614.png | Bin .../images/screenshot-2023-11-10-012641.png | Bin .../2974.Minimum Number Game/README.md | 88 +++++++++++++ .../2974.Minimum Number Game/README_EN.md | 78 ++++++++++++ .../README.md | 93 ++++++++++++++ .../README_EN.md | 83 +++++++++++++ .../images/maxsquareareaexample1.png | Bin 0 -> 5300 bytes .../screenshot-from-2023-11-05-22-40-25.png | Bin 0 -> 5058 bytes .../README.md | 108 ++++++++++++++++ .../README_EN.md | 92 ++++++++++++++ .../README.md | 117 ++++++++++++++++++ .../README_EN.md | 105 ++++++++++++++++ solution/CONTEST_README.md | 15 ++- solution/CONTEST_README_EN.md | 15 ++- solution/README.md | 22 ++-- solution/README_EN.md | 22 ++-- solution/main.py | 2 +- solution/summary.md | 10 +- solution/summary_en.md | 8 ++ 28 files changed, 852 insertions(+), 50 deletions(-) rename solution/{10000-10099/10031.Count the Number of Incremovable Subarrays I => 2900-2999/2970.Count the Number of Incremovable Subarrays I}/README.md (90%) rename solution/{10000-10099/10031.Count the Number of Incremovable Subarrays I => 2900-2999/2970.Count the Number of Incremovable Subarrays I}/README_EN.md (90%) rename solution/{10000-10099/10032.Find Polygon With the Largest Perimeter => 2900-2999/2971.Find Polygon With the Largest Perimeter}/README.md (92%) rename solution/{10000-10099/10032.Find Polygon With the Largest Perimeter => 2900-2999/2971.Find Polygon With the Largest Perimeter}/README_EN.md (92%) rename solution/{10000-10099/10033.Count the Number of Incremovable Subarrays II => 2900-2999/2972.Count the Number of Incremovable Subarrays II}/README.md (90%) rename solution/{10000-10099/10033.Count the Number of Incremovable Subarrays II => 2900-2999/2972.Count the Number of Incremovable Subarrays II}/README_EN.md (90%) rename solution/{10000-10099/10034.Find Number of Coins to Place in Tree Nodes => 2900-2999/2973.Find Number of Coins to Place in Tree Nodes}/README.md (83%) rename solution/{10000-10099/10034.Find Number of Coins to Place in Tree Nodes => 2900-2999/2973.Find Number of Coins to Place in Tree Nodes}/README_EN.md (81%) rename solution/{10000-10099/10034.Find Number of Coins to Place in Tree Nodes => 2900-2999/2973.Find Number of Coins to Place in Tree Nodes}/images/screenshot-2023-11-10-012513.png (100%) rename solution/{10000-10099/10034.Find Number of Coins to Place in Tree Nodes => 2900-2999/2973.Find Number of Coins to Place in Tree Nodes}/images/screenshot-2023-11-10-012614.png (100%) rename solution/{10000-10099/10034.Find Number of Coins to Place in Tree Nodes => 2900-2999/2973.Find Number of Coins to Place in Tree Nodes}/images/screenshot-2023-11-10-012641.png (100%) create mode 100644 solution/2900-2999/2974.Minimum Number Game/README.md create mode 100644 solution/2900-2999/2974.Minimum Number Game/README_EN.md create mode 100644 solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README.md create mode 100644 solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/README_EN.md create mode 100644 solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/images/maxsquareareaexample1.png create mode 100644 solution/2900-2999/2975.Maximum Square Area by Removing Fences From a Field/images/screenshot-from-2023-11-05-22-40-25.png create mode 100644 solution/2900-2999/2976.Minimum Cost to Convert String I/README.md create mode 100644 solution/2900-2999/2976.Minimum Cost to Convert String I/README_EN.md create mode 100644 solution/2900-2999/2977.Minimum Cost to Convert String II/README.md create mode 100644 solution/2900-2999/2977.Minimum Cost to Convert String II/README_EN.md diff --git a/solution/10000-10099/10031.Count the Number of Incremovable Subarrays I/README.md b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README.md similarity index 90% rename from solution/10000-10099/10031.Count the Number of Incremovable Subarrays I/README.md rename to solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README.md index 5052a2c5474b8..f5d679e62ba7c 100644 --- a/solution/10000-10099/10031.Count the Number of Incremovable Subarrays I/README.md +++ b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README.md @@ -1,6 +1,6 @@ -# [10031. 统计移除递增子数组的数目 I](https://leetcode.cn/problems/count-the-number-of-incremovable-subarrays-i) +# [2970. 统计移除递增子数组的数目 I](https://leetcode.cn/problems/count-the-number-of-incremovable-subarrays-i) -[English Version](/solution/10000-10099/10031.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README_EN.md) +[English Version](/solution/2900-2999/2970.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README_EN.md) ## 题目描述 diff --git a/solution/10000-10099/10031.Count the Number of Incremovable Subarrays I/README_EN.md b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README_EN.md similarity index 90% rename from solution/10000-10099/10031.Count the Number of Incremovable Subarrays I/README_EN.md rename to solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README_EN.md index 73c51d2512bf1..ee448266153f3 100644 --- a/solution/10000-10099/10031.Count the Number of Incremovable Subarrays I/README_EN.md +++ b/solution/2900-2999/2970.Count the Number of Incremovable Subarrays I/README_EN.md @@ -1,6 +1,6 @@ -# [10031. Count the Number of Incremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) +# [2970. Count the Number of Incremovable Subarrays I](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-i) -[中文文档](/solution/10000-10099/10031.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README.md) +[中文文档](/solution/2900-2999/2970.Count%20the%20Number%20of%20Incremovable%20Subarrays%20I/README.md) ## Description diff --git a/solution/10000-10099/10032.Find Polygon With the Largest Perimeter/README.md b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README.md similarity index 92% rename from solution/10000-10099/10032.Find Polygon With the Largest Perimeter/README.md rename to solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README.md index 82134d9808f7f..10b0c7313d2b3 100644 --- a/solution/10000-10099/10032.Find Polygon With the Largest Perimeter/README.md +++ b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README.md @@ -1,6 +1,6 @@ -# [10032. 找到最大周长的多边形](https://leetcode.cn/problems/find-polygon-with-the-largest-perimeter) +# [2971. 找到最大周长的多边形](https://leetcode.cn/problems/find-polygon-with-the-largest-perimeter) -[English Version](/solution/10000-10099/10032.Find%20Polygon%20With%20the%20Largest%20Perimeter/README_EN.md) +[English Version](/solution/2900-2999/2971.Find%20Polygon%20With%20the%20Largest%20Perimeter/README_EN.md) ## 题目描述 diff --git a/solution/10000-10099/10032.Find Polygon With the Largest Perimeter/README_EN.md b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README_EN.md similarity index 92% rename from solution/10000-10099/10032.Find Polygon With the Largest Perimeter/README_EN.md rename to solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README_EN.md index b6ed1d3532517..c5cf4e2076e08 100644 --- a/solution/10000-10099/10032.Find Polygon With the Largest Perimeter/README_EN.md +++ b/solution/2900-2999/2971.Find Polygon With the Largest Perimeter/README_EN.md @@ -1,6 +1,6 @@ -# [10032. Find Polygon With the Largest Perimeter](https://leetcode.com/problems/find-polygon-with-the-largest-perimeter) +# [2971. Find Polygon With the Largest Perimeter](https://leetcode.com/problems/find-polygon-with-the-largest-perimeter) -[中文文档](/solution/10000-10099/10032.Find%20Polygon%20With%20the%20Largest%20Perimeter/README.md) +[中文文档](/solution/2900-2999/2971.Find%20Polygon%20With%20the%20Largest%20Perimeter/README.md) ## Description diff --git a/solution/10000-10099/10033.Count the Number of Incremovable Subarrays II/README.md b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README.md similarity index 90% rename from solution/10000-10099/10033.Count the Number of Incremovable Subarrays II/README.md rename to solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README.md index 8e3d272377d9d..5ad5420d994a3 100644 --- a/solution/10000-10099/10033.Count the Number of Incremovable Subarrays II/README.md +++ b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README.md @@ -1,6 +1,6 @@ -# [10033. 统计移除递增子数组的数目 II](https://leetcode.cn/problems/count-the-number-of-incremovable-subarrays-ii) +# [2972. 统计移除递增子数组的数目 II](https://leetcode.cn/problems/count-the-number-of-incremovable-subarrays-ii) -[English Version](/solution/10000-10099/10033.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README_EN.md) +[English Version](/solution/2900-2999/2972.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README_EN.md) ## 题目描述 diff --git a/solution/10000-10099/10033.Count the Number of Incremovable Subarrays II/README_EN.md b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README_EN.md similarity index 90% rename from solution/10000-10099/10033.Count the Number of Incremovable Subarrays II/README_EN.md rename to solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README_EN.md index 26403a6c7035b..8e94f2be7fce9 100644 --- a/solution/10000-10099/10033.Count the Number of Incremovable Subarrays II/README_EN.md +++ b/solution/2900-2999/2972.Count the Number of Incremovable Subarrays II/README_EN.md @@ -1,6 +1,6 @@ -# [10033. Count the Number of Incremovable Subarrays II](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-ii) +# [2972. Count the Number of Incremovable Subarrays II](https://leetcode.com/problems/count-the-number-of-incremovable-subarrays-ii) -[中文文档](/solution/10000-10099/10033.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README.md) +[中文文档](/solution/2900-2999/2972.Count%20the%20Number%20of%20Incremovable%20Subarrays%20II/README.md) ## Description diff --git a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/README.md b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README.md similarity index 83% rename from solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/README.md rename to solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README.md index be16654bda485..88f9b1a6d6f99 100644 --- a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/README.md +++ b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README.md @@ -1,6 +1,6 @@ -# [10034. 树中每个节点放置的金币数目](https://leetcode.cn/problems/find-number-of-coins-to-place-in-tree-nodes) +# [2973. 树中每个节点放置的金币数目](https://leetcode.cn/problems/find-number-of-coins-to-place-in-tree-nodes) -[English Version](/solution/10000-10099/10034.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README_EN.md) +[English Version](/solution/2900-2999/2973.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README_EN.md) ## 题目描述 @@ -23,7 +23,7 @@
示例 1:
- +输入:edges = [[0,1],[0,2],[0,3],[0,4],[0,5]], cost = [1,2,3,4,5,6] @@ -33,7 +33,7 @@示例 2:
- +输入:edges = [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], cost = [1,4,2,3,5,7,8,-4,2] @@ -47,7 +47,7 @@示例 3:
- +输入:edges = [[0,1],[0,2]], cost = [1,2,-2] diff --git a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/README_EN.md b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README_EN.md similarity index 81% rename from solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/README_EN.md rename to solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README_EN.md index 39a5e9eeb1ff3..999fed7da5917 100644 --- a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/README_EN.md +++ b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/README_EN.md @@ -1,6 +1,6 @@ -# [10034. Find Number of Coins to Place in Tree Nodes](https://leetcode.com/problems/find-number-of-coins-to-place-in-tree-nodes) +# [2973. Find Number of Coins to Place in Tree Nodes](https://leetcode.com/problems/find-number-of-coins-to-place-in-tree-nodes) -[中文文档](/solution/10000-10099/10034.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README.md) +[中文文档](/solution/2900-2999/2973.Find%20Number%20of%20Coins%20to%20Place%20in%20Tree%20Nodes/README.md) ## Description @@ -19,7 +19,7 @@
Example 1:
- +Input: edges = [[0,1],[0,2],[0,3],[0,4],[0,5]], cost = [1,2,3,4,5,6] Output: [120,1,1,1,1,1] @@ -27,7 +27,7 @@Example 2:
- +Input: edges = [[0,1],[0,2],[1,3],[1,4],[1,5],[2,6],[2,7],[2,8]], cost = [1,4,2,3,5,7,8,-4,2] Output: [280,140,32,1,1,1,1,1,1] @@ -39,7 +39,7 @@Example 3:
- +Input: edges = [[0,1],[0,2]], cost = [1,2,-2] Output: [0,1,1] diff --git a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012513.png b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012513.png similarity index 100% rename from solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012513.png rename to solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012513.png diff --git a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012614.png b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012614.png similarity index 100% rename from solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012614.png rename to solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012614.png diff --git a/solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012641.png b/solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012641.png similarity index 100% rename from solution/10000-10099/10034.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012641.png rename to solution/2900-2999/2973.Find Number of Coins to Place in Tree Nodes/images/screenshot-2023-11-10-012641.png diff --git a/solution/2900-2999/2974.Minimum Number Game/README.md b/solution/2900-2999/2974.Minimum Number Game/README.md new file mode 100644 index 0000000000000..7d8f07198dfa5 --- /dev/null +++ b/solution/2900-2999/2974.Minimum Number Game/README.md @@ -0,0 +1,88 @@ +# [2974. 最小数字游戏](https://leetcode.cn/problems/minimum-number-game) + +[English Version](/solution/2900-2999/2974.Minimum%20Number%20Game/README_EN.md) + +## 题目描述 + + + +你有一个下标从 0 开始、长度为 偶数 的整数数组
+ +nums
,同时还有一个空数组arr
。Alice 和 Bob 决定玩一个游戏,游戏中每一轮 Alice 和 Bob 都会各自执行一次操作。游戏规则如下:
nums
中移除一个 最小 元素,然后 Bob 执行同样的操作。arr
中,然后 Alice 也执行同样的操作。nums
变为空。返回结果数组 arr
。
+ +
示例 1:
+ ++输入:nums = [5,4,2,3] +输出:[3,2,5,4] +解释:第一轮,Alice 先移除 2 ,然后 Bob 移除 3 。然后 Bob 先将 3 添加到 arr 中,接着 Alice 再将 2 添加到 arr 中。于是 arr = [3,2] 。 +第二轮开始时,nums = [5,4] 。Alice 先移除 4 ,然后 Bob 移除 5 。接着他们都将元素添加到 arr 中,arr 变为 [3,2,5,4] 。 ++ +
示例 2:
+ ++输入:nums = [2,5] +输出:[5,2] +解释:第一轮,Alice 先移除 2 ,然后 Bob 移除 5 。然后 Bob 先将 5 添加到 arr 中,接着 Alice 再将 2 添加到 arr 中。于是 arr = [5,2] 。 ++ +
+ +
提示:
+ +1 <= nums.length <= 100
1 <= nums[i] <= 100
nums.length % 2 == 0
You are given a 0-indexed integer array nums
of even length and there is also an empty array arr
. Alice and Bob decided to play a game where in every round Alice and Bob will do one move. The rules of the game are as follows:
nums
, and then Bob does the same.arr
, and then Alice does the same.nums
becomes empty.Return the resulting array arr
.
+
Example 1:
+ ++Input: nums = [5,4,2,3] +Output: [3,2,5,4] +Explanation: In round one, first Alice removes 2 and then Bob removes 3. Then in arr firstly Bob appends 3 and then Alice appends 2. So arr = [3,2]. +At the begining of round two, nums = [5,4]. Now, first Alice removes 4 and then Bob removes 5. Then both append in arr which becomes [3,2,5,4]. ++ +
Example 2:
+ ++Input: nums = [2,5] +Output: [5,2] +Explanation: In round one, first Alice removes 2 and then Bob removes 5. Then in arr firstly Bob appends and then Alice appends. So arr = [5,2]. ++ +
+
Constraints:
+ +1 <= nums.length <= 100
1 <= nums[i] <= 100
nums.length % 2 == 0
有一个大型的 (m - 1) x (n - 1)
矩形田地,其两个对角分别是 (1, 1)
和 (m, n)
,田地内部有一些水平栅栏和垂直栅栏,分别由数组 hFences
和 vFences
给出。
水平栅栏为坐标 (hFences[i], 1)
到 (hFences[i], n)
,垂直栅栏为坐标 (1, vFences[i])
到 (m, vFences[i])
。
返回通过 移除 一些栅栏(可能不移除)所能形成的最大面积的 正方形 田地的面积,或者如果无法形成正方形田地则返回 -1
。
由于答案可能很大,所以请返回结果对 109 + 7
取余 后的值。
注意:田地外围两个水平栅栏(坐标 (1, 1)
到 (1, n)
和坐标 (m, 1)
到 (m, n)
)以及两个垂直栅栏(坐标 (1, 1)
到 (m, 1)
和坐标 (1, n)
到 (m, n)
)所包围。这些栅栏 不能 被移除。
+ +
示例 1:
+ + + ++输入:m = 4, n = 3, hFences = [2,3], vFences = [2] +输出:4 +解释:移除位于 2 的水平栅栏和位于 2 的垂直栅栏将得到一个面积为 4 的正方形田地。 ++ +
示例 2:
+ + + ++输入:m = 6, n = 7, hFences = [2], vFences = [4] +输出:-1 +解释:可以证明无法通过移除栅栏形成正方形田地。 ++ +
+ +
提示:
+ +3 <= m, n <= 109
1 <= hFences.length, vFences.length <= 600
1 < hFences[i] < m
1 < vFences[i] < n
hFences
和 vFences
中的元素是唯一的。There is a large (m - 1) x (n - 1)
rectangular field with corners at (1, 1)
and (m, n)
containing some horizontal and vertical fences given in arrays hFences
and vFences
respectively.
Horizontal fences are from the coordinates (hFences[i], 1)
to (hFences[i], n)
and vertical fences are from the coordinates (1, vFences[i])
to (m, vFences[i])
.
Return the maximum area of a square field that can be formed by removing some fences (possibly none) or -1
if it is impossible to make a square field.
Since the answer may be large, return it modulo 109 + 7
.
Note: The field is surrounded by two horizontal fences from the coordinates (1, 1)
to (1, n)
and (m, 1)
to (m, n)
and two vertical fences from the coordinates (1, 1)
to (m, 1)
and (1, n)
to (m, n)
. These fences cannot be removed.
+
Example 1:
+ + + ++Input: m = 4, n = 3, hFences = [2,3], vFences = [2] +Output: 4 +Explanation: Removing the horizontal fence at 2 and the vertical fence at 2 will give a square field of area 4. ++ +
Example 2:
+ + + ++Input: m = 6, n = 7, hFences = [2], vFences = [4] +Output: -1 +Explanation: It can be proved that there is no way to create a square field by removing fences. ++ +
+
Constraints:
+ +3 <= m, n <= 109
1 <= hFences.length, vFences.length <= 600
1 < hFences[i] < m
1 < vFences[i] < n
hFences
and vFences
are unique.