From c51e22fbcc8f3e831e2ed24fdcd61ea637796254 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Mon, 30 Oct 2023 09:39:16 +0800 Subject: [PATCH] feat: add biweekly contest 116 and weekly contest 369 (#1898) * feat: add biweekly contest 116 and weekly contest 369 * chore: optimised images with calibre/image-actions --------- Co-authored-by: Doocs Bot --- .../README.md | 101 ++++++++++++++++ .../README_EN.md | 88 ++++++++++++++ .../README.md | 102 ++++++++++++++++ .../README_EN.md | 92 ++++++++++++++ .../README.md | 91 ++++++++++++++ .../README_EN.md | 81 +++++++++++++ .../README.md | 101 ++++++++++++++++ .../README_EN.md | 90 ++++++++++++++ .../2917.Find the K-or of an Array/README.md | 100 +++++++++++++++ .../README_EN.md | 91 ++++++++++++++ .../README.md | 85 +++++++++++++ .../README_EN.md | 75 ++++++++++++ .../README.md | 114 ++++++++++++++++++ .../README_EN.md | 104 ++++++++++++++++ .../README.md | 100 +++++++++++++++ .../README_EN.md | 90 ++++++++++++++ .../images/ex1-copy.png | Bin 0 -> 5602 bytes .../images/ex2.png | Bin 0 -> 4314 bytes solution/CONTEST_README.md | 14 +++ solution/CONTEST_README_EN.md | 14 +++ solution/README.md | 8 ++ solution/README_EN.md | 8 ++ solution/summary.md | 8 ++ solution/summary_en.md | 8 ++ 24 files changed, 1565 insertions(+) create mode 100644 solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README.md create mode 100644 solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README_EN.md create mode 100644 solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README.md create mode 100644 solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README_EN.md create mode 100644 solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README.md create mode 100644 solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README_EN.md create mode 100644 solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README.md create mode 100644 solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README_EN.md create mode 100644 solution/2900-2999/2917.Find the K-or of an Array/README.md create mode 100644 solution/2900-2999/2917.Find the K-or of an Array/README_EN.md create mode 100644 solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README.md create mode 100644 solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README_EN.md create mode 100644 solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README.md create mode 100644 solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README_EN.md create mode 100644 solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README.md create mode 100644 solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README_EN.md create mode 100644 solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/images/ex1-copy.png create mode 100644 solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/images/ex2.png diff --git a/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README.md b/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README.md new file mode 100644 index 0000000000000..74df06f8ac071 --- /dev/null +++ b/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README.md @@ -0,0 +1,101 @@ +# [2913. 子数组不同元素数目的平方和 I](https://leetcode.cn/problems/subarrays-distinct-element-sum-of-squares-i) + +[English Version](/solution/2900-2999/2913.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20I/README_EN.md) + +## 题目描述 + + + +

给你一个下标从 0 开始的整数数组 nums 。

+ +

定义 nums 一个子数组的 不同计数 值如下:

+ + + +

请你返回 nums 中所有子数组的 不同计数 的 平方 和。

+ +

由于答案可能会很大,请你将它对 109 + 7 取余 后返回。

+ +

子数组指的是一个数组里面一段连续 非空 的元素序列。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [1,2,1]
+输出:15
+解释:六个子数组分别为:
+[1]: 1 个互不相同的元素。
+[2]: 1 个互不相同的元素。
+[1]: 1 个互不相同的元素。
+[1,2]: 2 个互不相同的元素。
+[2,1]: 2 个互不相同的元素。
+[1,2,1]: 2 个互不相同的元素。
+所有不同计数的平方和为 12 + 12 + 12 + 22 + 22 + 22 = 15 。
+
+ +

示例 2:

+ +
+输入:nums = [2,2]
+输出:3
+解释:三个子数组分别为:
+[2]: 1 个互不相同的元素。
+[2]: 1 个互不相同的元素。
+[2,2]: 1 个互不相同的元素。
+所有不同计数的平方和为 12 + 12 + 12 = 3 。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README_EN.md b/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README_EN.md new file mode 100644 index 0000000000000..db319da3a4143 --- /dev/null +++ b/solution/2900-2999/2913.Subarrays Distinct Element Sum of Squares I/README_EN.md @@ -0,0 +1,88 @@ +# [2913. Subarrays Distinct Element Sum of Squares I](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i) + +[中文文档](/solution/2900-2999/2913.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20I/README.md) + +## Description + +

You are given a 0-indexed integer array nums.

+ +

The distinct count of a subarray of nums is defined as:

+ + + +

Return the sum of the squares of distinct counts of all subarrays of nums.

+ +

A subarray is a contiguous non-empty sequence of elements within an array.

+ +

 

+

Example 1:

+ +
+Input: nums = [1,2,1]
+Output: 15
+Explanation: Six possible subarrays are:
+[1]: 1 distinct value
+[2]: 1 distinct value
+[1]: 1 distinct value
+[1,2]: 2 distinct values
+[2,1]: 2 distinct values
+[1,2,1]: 2 distinct values
+The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 + 22 + 22 + 22 = 15.
+
+ +

Example 2:

+ +
+Input: nums = [1,1]
+Output: 3
+Explanation: Three possible subarrays are:
+[1]: 1 distinct value
+[1]: 1 distinct value
+[1,1]: 1 distinct value
+The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 = 3.
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README.md b/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README.md new file mode 100644 index 0000000000000..3e456c39dcfca --- /dev/null +++ b/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README.md @@ -0,0 +1,102 @@ +# [2914. 使二进制字符串变美丽的最少修改次数](https://leetcode.cn/problems/minimum-number-of-changes-to-make-binary-string-beautiful) + +[English Version](/solution/2900-2999/2914.Minimum%20Number%20of%20Changes%20to%20Make%20Binary%20String%20Beautiful/README_EN.md) + +## 题目描述 + + + +

给你一个长度为偶数下标从 0 开始的二进制字符串 s 。

+ +

如果可以将一个字符串分割成一个或者更多满足以下条件的子字符串,那么我们称这个字符串是 美丽的 :

+ + + +

你可以将 s 中任一字符改成 0 或者 1 。

+ +

请你返回让字符串 s 美丽的 最少 字符修改次数。

+ +

 

+ +

示例 1:

+ +
+输入:s = "1001"
+输出:2
+解释:我们将 s[1] 改为 1 ,且将 s[3] 改为 0 ,得到字符串 "1100" 。
+字符串 "1100" 是美丽的,因为我们可以将它分割成 "11|00" 。
+将字符串变美丽最少需要 2 次修改。
+
+ +

示例 2:

+ +
+输入:s = "10"
+输出:1
+解释:我们将 s[1] 改为 1 ,得到字符串 "11" 。
+字符串 "11" 是美丽的,因为它已经是美丽的。
+将字符串变美丽最少需要 1 次修改。
+
+ +

示例 3:

+ +
+输入:s = "0000"
+输出:0
+解释:不需要进行任何修改,字符串 "0000" 已经是美丽字符串。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README_EN.md b/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README_EN.md new file mode 100644 index 0000000000000..85a086dc7af46 --- /dev/null +++ b/solution/2900-2999/2914.Minimum Number of Changes to Make Binary String Beautiful/README_EN.md @@ -0,0 +1,92 @@ +# [2914. Minimum Number of Changes to Make Binary String Beautiful](https://leetcode.com/problems/minimum-number-of-changes-to-make-binary-string-beautiful) + +[中文文档](/solution/2900-2999/2914.Minimum%20Number%20of%20Changes%20to%20Make%20Binary%20String%20Beautiful/README.md) + +## Description + +

You are given a 0-indexed binary string s having an even length.

+ +

A string is beautiful if it's possible to partition it into one or more substrings such that:

+ + + +

You can change any character in s to 0 or 1.

+ +

Return the minimum number of changes required to make the string s beautiful.

+ +

 

+

Example 1:

+ +
+Input: s = "1001"
+Output: 2
+Explanation: We change s[1] to 1 and s[3] to 0 to get string "1100".
+It can be seen that the string "1100" is beautiful because we can partition it into "11|00".
+It can be proven that 2 is the minimum number of changes needed to make the string beautiful.
+
+ +

Example 2:

+ +
+Input: s = "10"
+Output: 1
+Explanation: We change s[1] to 1 to get string "11".
+It can be seen that the string "11" is beautiful because we can partition it into "11".
+It can be proven that 1 is the minimum number of changes needed to make the string beautiful.
+
+ +

Example 3:

+ +
+Input: s = "0000"
+Output: 0
+Explanation: We don't need to make any changes as the string "0000" is beautiful already.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README.md b/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README.md new file mode 100644 index 0000000000000..72c90594de2f8 --- /dev/null +++ b/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README.md @@ -0,0 +1,91 @@ +# [2915. 和为目标值的最长子序列的长度](https://leetcode.cn/problems/length-of-the-longest-subsequence-that-sums-to-target) + +[English Version](/solution/2900-2999/2915.Length%20of%20the%20Longest%20Subsequence%20That%20Sums%20to%20Target/README_EN.md) + +## 题目描述 + + + +

给你一个下标从 0 开始的整数数组 nums 和一个整数 target 。

+ +

返回和为 target 的 nums 子序列中,子序列 长度的最大值 。如果不存在和为 target 的子序列,返回 -1 。

+ +

子序列 指的是从原数组中删除一些或者不删除任何元素后,剩余元素保持原来的顺序构成的数组。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [1,2,3,4,5], target = 9
+输出:3
+解释:总共有 3 个子序列的和为 9 :[4,5] ,[1,3,5] 和 [2,3,4] 。最长的子序列是 [1,3,5] 和 [2,3,4] 。所以答案为 3 。
+
+ +

示例 2:

+ +
+输入:nums = [4,1,3,2,1,5], target = 7
+输出:4
+解释:总共有 5 个子序列的和为 7 :[4,3] ,[4,1,2] ,[4,2,1] ,[1,1,5] 和 [1,3,2,1] 。最长子序列为 [1,3,2,1] 。所以答案为 4 。
+
+ +

示例 3:

+ +
+输入:nums = [1,1,5,4,5], target = 3
+输出:-1
+解释:无法得到和为 3 的子序列。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README_EN.md b/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README_EN.md new file mode 100644 index 0000000000000..5903ef24b1248 --- /dev/null +++ b/solution/2900-2999/2915.Length of the Longest Subsequence That Sums to Target/README_EN.md @@ -0,0 +1,81 @@ +# [2915. Length of the Longest Subsequence That Sums to Target](https://leetcode.com/problems/length-of-the-longest-subsequence-that-sums-to-target) + +[中文文档](/solution/2900-2999/2915.Length%20of%20the%20Longest%20Subsequence%20That%20Sums%20to%20Target/README.md) + +## Description + +

You are given a 0-indexed array of integers nums, and an integer target.

+ +

Return the length of the longest subsequence of nums that sums up to target. If no such subsequence exists, return -1.

+ +

A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.

+ +

 

+

Example 1:

+ +
+Input: nums = [1,2,3,4,5], target = 9
+Output: 3
+Explanation: There are 3 subsequences with a sum equal to 9: [4,5], [1,3,5], and [2,3,4]. The longest subsequences are [1,3,5], and [2,3,4]. Hence, the answer is 3.
+
+ +

Example 2:

+ +
+Input: nums = [4,1,3,2,1,5], target = 7
+Output: 4
+Explanation: There are 5 subsequences with a sum equal to 7: [4,3], [4,1,2], [4,2,1], [1,1,5], and [1,3,2,1]. The longest subsequence is [1,3,2,1]. Hence, the answer is 4.
+
+ +

Example 3:

+ +
+Input: nums = [1,1,5,4,5], target = 3
+Output: -1
+Explanation: It can be shown that nums has no subsequence that sums up to 3.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README.md b/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README.md new file mode 100644 index 0000000000000..71ece64bd758c --- /dev/null +++ b/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README.md @@ -0,0 +1,101 @@ +# [2916. 子数组不同元素数目的平方和 II](https://leetcode.cn/problems/subarrays-distinct-element-sum-of-squares-ii) + +[English Version](/solution/2900-2999/2916.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20II/README_EN.md) + +## 题目描述 + + + +

给你一个下标从 0 开始的整数数组 nums 。

+ +

定义 nums 一个子数组的 不同计数 值如下:

+ + + +

请你返回 nums 中所有子数组的 不同计数 的 平方 和。

+ +

由于答案可能会很大,请你将它对 109 + 7 取余 后返回。

+ +

子数组指的是一个数组里面一段连续 非空 的元素序列。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [1,2,1]
+输出:15
+解释:六个子数组分别为:
+[1]: 1 个互不相同的元素。
+[2]: 1 个互不相同的元素。
+[1]: 1 个互不相同的元素。
+[1,2]: 2 个互不相同的元素。
+[2,1]: 2 个互不相同的元素。
+[1,2,1]: 2 个互不相同的元素。
+所有不同计数的平方和为 12 + 12 + 12 + 22 + 22 + 22 = 15 。
+
+ +

示例 2:

+ +
+输入:nums = [2,2]
+输出:3
+解释:三个子数组分别为:
+[2]: 1 个互不相同的元素。
+[2]: 1 个互不相同的元素。
+[2,2]: 1 个互不相同的元素。
+所有不同计数的平方和为 12 + 12 + 12 = 3 。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README_EN.md b/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README_EN.md new file mode 100644 index 0000000000000..45a8a9a509223 --- /dev/null +++ b/solution/2900-2999/2916.Subarrays Distinct Element Sum of Squares II/README_EN.md @@ -0,0 +1,90 @@ +# [2916. Subarrays Distinct Element Sum of Squares II](https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-ii) + +[中文文档](/solution/2900-2999/2916.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20II/README.md) + +## Description + +

You are given a 0-indexed integer array nums.

+ +

The distinct count of a subarray of nums is defined as:

+ + + +

Return the sum of the squares of distinct counts of all subarrays of nums.

+ +

Since the answer may be very large, return it modulo 109 + 7.

+ +

A subarray is a contiguous non-empty sequence of elements within an array.

+ +

 

+

Example 1:

+ +
+Input: nums = [1,2,1]
+Output: 15
+Explanation: Six possible subarrays are:
+[1]: 1 distinct value
+[2]: 1 distinct value
+[1]: 1 distinct value
+[1,2]: 2 distinct values
+[2,1]: 2 distinct values
+[1,2,1]: 2 distinct values
+The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 + 22 + 22 + 22 = 15.
+
+ +

Example 2:

+ +
+Input: nums = [2,2]
+Output: 3
+Explanation: Three possible subarrays are:
+[2]: 1 distinct value
+[2]: 1 distinct value
+[2,2]: 1 distinct value
+The sum of the squares of the distinct counts in all subarrays is equal to 12 + 12 + 12 = 3.
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2917.Find the K-or of an Array/README.md b/solution/2900-2999/2917.Find the K-or of an Array/README.md new file mode 100644 index 0000000000000..10fe261d86620 --- /dev/null +++ b/solution/2900-2999/2917.Find the K-or of an Array/README.md @@ -0,0 +1,100 @@ +# [2917. 找出数组中的 K-or 值](https://leetcode.cn/problems/find-the-k-or-of-an-array) + +[English Version](/solution/2900-2999/2917.Find%20the%20K-or%20of%20an%20Array/README_EN.md) + +## 题目描述 + + + +

给你一个下标从 0 开始的整数数组 nums 和一个整数 k

+ +

nums 中的 K-or 是一个满足以下条件的非负整数:

+ + + +

返回 numsK-or 值。

+ +

注意 :对于整数 x ,如果 (2i AND x) == 2i ,则 x 中的第 i 位值为 1 ,其中 AND 为按位与运算符。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [7,12,9,8,9,15], k = 4
+输出:9
+解释:nums[0]、nums[2]、nums[4] 和 nums[5] 的第 0 位的值为 1 。
+nums[0] 和 nums[5] 的第 1 位的值为 1 。
+nums[0]、nums[1] 和 nums[5] 的第 2 位的值为 1 。
+nums[1]、nums[2]、nums[3]、nums[4] 和 nums[5] 的第 3 位的值为 1 。
+只有第 0 位和第 3 位满足数组中至少存在 k 个元素在对应位上的值为 1 。因此,答案为 2^0 + 2^3 = 9 。
+
+ +

示例 2:

+ +
+输入:nums = [2,12,1,11,4,5], k = 6
+输出:0
+解释:因为 k == 6 == nums.length ,所以数组的 6-or 等于其中所有元素按位与运算的结果。因此,答案为 2 AND 12 AND 1 AND 11 AND 4 AND 5 = 0 。
+
+ +

示例 3:

+ +
+输入:nums = [10,8,5,9,11,6,8], k = 1
+输出:15
+解释:因为 k == 1 ,数组的 1-or 等于其中所有元素按位或运算的结果。因此,答案为 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15 。
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2917.Find the K-or of an Array/README_EN.md b/solution/2900-2999/2917.Find the K-or of an Array/README_EN.md new file mode 100644 index 0000000000000..ccfa7d9d79c24 --- /dev/null +++ b/solution/2900-2999/2917.Find the K-or of an Array/README_EN.md @@ -0,0 +1,91 @@ +# [2917. Find the K-or of an Array](https://leetcode.com/problems/find-the-k-or-of-an-array) + +[中文文档](/solution/2900-2999/2917.Find%20the%20K-or%20of%20an%20Array/README.md) + +## Description + +

You are given a 0-indexed integer array nums, and an integer k.

+ +

The K-or of nums is a non-negative integer that satisfies the following:

+ + + +

Return the K-or of nums.

+ +

Note that a bit i is set in x if (2i AND x) == 2i, where AND is the bitwise AND operator.

+ +

 

+

Example 1:

+ +
+Input: nums = [7,12,9,8,9,15], k = 4
+Output: 9
+Explanation: Bit 0 is set at nums[0], nums[2], nums[4], and nums[5].
+Bit 1 is set at nums[0], and nums[5].
+Bit 2 is set at nums[0], nums[1], and nums[5].
+Bit 3 is set at nums[1], nums[2], nums[3], nums[4], and nums[5].
+Only bits 0 and 3 are set in at least k elements of the array, and bits i >= 4 are not set in any of the array's elements. Hence, the answer is 2^0 + 2^3 = 9.
+
+ +

Example 2:

+ +
+Input: nums = [2,12,1,11,4,5], k = 6
+Output: 0
+Explanation: Since k == 6 == nums.length, the 6-or of the array is equal to the bitwise AND of all its elements. Hence, the answer is 2 AND 12 AND 1 AND 11 AND 4 AND 5 = 0.
+
+ +

Example 3:

+ +
+Input: nums = [10,8,5,9,11,6,8], k = 1
+Output: 15
+Explanation: Since k == 1, the 1-or of the array is equal to the bitwise OR of all its elements. Hence, the answer is 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README.md b/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README.md new file mode 100644 index 0000000000000..fb70b19b07ac6 --- /dev/null +++ b/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README.md @@ -0,0 +1,85 @@ +# [2918. 数组的最小相等和](https://leetcode.cn/problems/minimum-equal-sum-of-two-arrays-after-replacing-zeros) + +[English Version](/solution/2900-2999/2918.Minimum%20Equal%20Sum%20of%20Two%20Arrays%20After%20Replacing%20Zeros/README_EN.md) + +## 题目描述 + + + +

给你两个由正整数和 0 组成的数组 nums1nums2

+ +

你必须将两个数组中的 所有 0 替换为 严格 正整数,并且满足两个数组中所有元素的和 相等

+ +

返回 最小 相等和 ,如果无法使两数组相等,则返回 -1

+ +

 

+ +

示例 1:

+ +
+输入:nums1 = [3,2,0,1,0], nums2 = [6,5,0]
+输出:12
+解释:可以按下述方式替换数组中的 0 :
+- 用 2 和 4 替换 nums1 中的两个 0 。得到 nums1 = [3,2,2,1,4] 。
+- 用 1 替换 nums2 中的一个 0 。得到 nums2 = [6,5,1] 。
+两个数组的元素和相等,都等于 12 。可以证明这是可以获得的最小相等和。
+
+ +

示例 2:

+ +
+输入:nums1 = [2,0,2,0], nums2 = [1,4]
+输出:-1
+解释:无法使两个数组的和相等。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README_EN.md b/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README_EN.md new file mode 100644 index 0000000000000..9d05efb1148f2 --- /dev/null +++ b/solution/2900-2999/2918.Minimum Equal Sum of Two Arrays After Replacing Zeros/README_EN.md @@ -0,0 +1,75 @@ +# [2918. Minimum Equal Sum of Two Arrays After Replacing Zeros](https://leetcode.com/problems/minimum-equal-sum-of-two-arrays-after-replacing-zeros) + +[中文文档](/solution/2900-2999/2918.Minimum%20Equal%20Sum%20of%20Two%20Arrays%20After%20Replacing%20Zeros/README.md) + +## Description + +

You are given two arrays nums1 and nums2 consisting of positive integers.

+ +

You have to replace all the 0's in both arrays with strictly positive integers such that the sum of elements of both arrays becomes equal.

+ +

Return the minimum equal sum you can obtain, or -1 if it is impossible.

+ +

 

+

Example 1:

+ +
+Input: nums1 = [3,2,0,1,0], nums2 = [6,5,0]
+Output: 12
+Explanation: We can replace 0's in the following way:
+- Replace the two 0's in nums1 with the values 2 and 4. The resulting array is nums1 = [3,2,2,1,4].
+- Replace the 0 in nums2 with the value 1. The resulting array is nums2 = [6,5,1].
+Both arrays have an equal sum of 12. It can be shown that it is the minimum sum we can obtain.
+
+ +

Example 2:

+ +
+Input: nums1 = [2,0,2,0], nums2 = [1,4]
+Output: -1
+Explanation: It is impossible to make the sum of both arrays equal.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README.md b/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README.md new file mode 100644 index 0000000000000..ec401b101772e --- /dev/null +++ b/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README.md @@ -0,0 +1,114 @@ +# [2919. 使数组变美的最小增量运算数](https://leetcode.cn/problems/minimum-increment-operations-to-make-array-beautiful) + +[English Version](/solution/2900-2999/2919.Minimum%20Increment%20Operations%20to%20Make%20Array%20Beautiful/README_EN.md) + +## 题目描述 + + + +

给你一个下标从 0 开始、长度为 n 的整数数组 nums ,和一个整数 k

+ +

你可以执行下述 递增 运算 任意 次(可以是 0 次):

+ + + +

如果数组中任何长度 大于或等于 3 的子数组,其 最大 元素都大于或等于 k ,则认为数组是一个 美丽数组

+ +

以整数形式返回使数组变为 美丽数组 需要执行的 最小 递增运算数。

+ +

子数组是数组中的一个连续 非空 元素序列。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [2,3,0,0,2], k = 4
+输出:3
+解释:可以执行下述递增运算,使 nums 变为美丽数组:
+选择下标 i = 1 ,并且将 nums[1] 的值加 1 -> [2,4,0,0,2] 。
+选择下标 i = 4 ,并且将 nums[4] 的值加 1 -> [2,4,0,0,3] 。
+选择下标 i = 4 ,并且将 nums[4] 的值加 1 -> [2,4,0,0,4] 。
+长度大于或等于 3 的子数组为 [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4] 。
+在所有子数组中,最大元素都等于 k = 4 ,所以 nums 现在是美丽数组。
+可以证明无法用少于 3 次递增运算使 nums 变为美丽数组。
+因此,答案为 3 。
+
+ +

示例 2:

+ +
+输入:nums = [0,1,3,3], k = 5
+输出:2
+解释:可以执行下述递增运算,使 nums 变为美丽数组:
+选择下标 i = 2 ,并且将 nums[2] 的值加 1 -> [0,1,4,3] 。
+选择下标 i = 2 ,并且将 nums[2] 的值加 1 -> [0,1,5,3] 。
+长度大于或等于 3 的子数组为 [0,1,5]、[1,5,3]、[0,1,5,3] 。
+在所有子数组中,最大元素都等于 k = 5 ,所以 nums 现在是美丽数组。
+可以证明无法用少于 2 次递增运算使 nums 变为美丽数组。 
+因此,答案为 2 。
+
+ +

示例 3:

+ +
+输入:nums = [1,1,2], k = 1
+输出:0
+解释:在这个示例中,只有一个长度大于或等于 3 的子数组 [1,1,2] 。
+其最大元素 2 已经大于 k = 1 ,所以无需执行任何增量运算。
+因此,答案为 0 。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README_EN.md b/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README_EN.md new file mode 100644 index 0000000000000..d3820c07ecaaa --- /dev/null +++ b/solution/2900-2999/2919.Minimum Increment Operations to Make Array Beautiful/README_EN.md @@ -0,0 +1,104 @@ +# [2919. Minimum Increment Operations to Make Array Beautiful](https://leetcode.com/problems/minimum-increment-operations-to-make-array-beautiful) + +[中文文档](/solution/2900-2999/2919.Minimum%20Increment%20Operations%20to%20Make%20Array%20Beautiful/README.md) + +## Description + +

You are given a 0-indexed integer array nums having length n, and an integer k.

+ +

You can perform the following increment operation any number of times (including zero):

+ + + +

An array is considered beautiful if, for any subarray with a size of 3 or more, its maximum element is greater than or equal to k.

+ +

Return an integer denoting the minimum number of increment operations needed to make nums beautiful.

+ +

A subarray is a contiguous non-empty sequence of elements within an array.

+ +

 

+

Example 1:

+ +
+Input: nums = [2,3,0,0,2], k = 4
+Output: 3
+Explanation: We can perform the following increment operations to make nums beautiful:
+Choose index i = 1 and increase nums[1] by 1 -> [2,4,0,0,2].
+Choose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,3].
+Choose index i = 4 and increase nums[4] by 1 -> [2,4,0,0,4].
+The subarrays with a size of 3 or more are: [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4].
+In all the subarrays, the maximum element is equal to k = 4, so nums is now beautiful.
+It can be shown that nums cannot be made beautiful with fewer than 3 increment operations.
+Hence, the answer is 3.
+
+ +

Example 2:

+ +
+Input: nums = [0,1,3,3], k = 5
+Output: 2
+Explanation: We can perform the following increment operations to make nums beautiful:
+Choose index i = 2 and increase nums[2] by 1 -> [0,1,4,3].
+Choose index i = 2 and increase nums[2] by 1 -> [0,1,5,3].
+The subarrays with a size of 3 or more are: [0,1,5], [1,5,3], [0,1,5,3].
+In all the subarrays, the maximum element is equal to k = 5, so nums is now beautiful.
+It can be shown that nums cannot be made beautiful with fewer than 2 increment operations.
+Hence, the answer is 2.
+
+ +

Example 3:

+ +
+Input: nums = [1,1,2], k = 1
+Output: 0
+Explanation: The only subarray with a size of 3 or more in this example is [1,1,2].
+The maximum element, 2, is already greater than k = 1, so we don't need any increment operation.
+Hence, the answer is 0.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README.md b/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README.md new file mode 100644 index 0000000000000..5a8d0001de7c9 --- /dev/null +++ b/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README.md @@ -0,0 +1,100 @@ +# [2920. 收集所有金币可获得的最大积分](https://leetcode.cn/problems/maximum-points-after-collecting-coins-from-all-nodes) + +[English Version](/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/README_EN.md) + +## 题目描述 + + + +

节点 0 处现有一棵由 n 个节点组成的无向树,节点编号从 0n - 1 。给你一个长度为 n - 1 的二维 整数 数组 edges ,其中 edges[i] = [ai, bi] 表示在树上的节点 aibi 之间存在一条边。另给你一个下标从 0 开始、长度为 n 的数组 coins 和一个整数 k ,其中 coins[i] 表示节点 i 处的金币数量。

+ +

从根节点开始,你必须收集所有金币。要想收集节点上的金币,必须先收集该节点的祖先节点上的金币。

+ +

节点 i 上的金币可以用下述方法之一进行收集:

+ + + +

返回收集 所有 树节点的金币之后可以获得的最大积分。

+ +

 

+ +

示例 1:

+ +
+输入:edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5
+输出:11                        
+解释:
+使用第一种方法收集节点 0 上的所有金币。总积分 = 10 - 5 = 5 。
+使用第一种方法收集节点 1 上的所有金币。总积分 = 5 + (10 - 5) = 10 。
+使用第二种方法收集节点 2 上的所有金币。所以节点 3 上的金币将会变为 floor(3 / 2) = 1 ,总积分 = 10 + floor(3 / 2) = 11 。
+使用第二种方法收集节点 3 上的所有金币。总积分 =  11 + floor(1 / 2) = 11.
+可以证明收集所有节点上的金币能获得的最大积分是 11 。 
+
+ +

示例 2:

+ + +
+输入:edges = [[0,1],[0,2]], coins = [8,4,4], k = 0
+输出:16
+解释:
+使用第一种方法收集所有节点上的金币,因此,总积分 = (8 - 0) + (4 - 0) + (4 - 0) = 16 。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README_EN.md b/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README_EN.md new file mode 100644 index 0000000000000..37ed176f0f042 --- /dev/null +++ b/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/README_EN.md @@ -0,0 +1,90 @@ +# [2920. Maximum Points After Collecting Coins From All Nodes](https://leetcode.com/problems/maximum-points-after-collecting-coins-from-all-nodes) + +[中文文档](/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/README.md) + +## Description + +

There exists an undirected tree rooted at node 0 with n nodes labeled from 0 to n - 1. You are given a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree. You are also given a 0-indexed array coins of size n where coins[i] indicates the number of coins in the vertex i, and an integer k.

+ +

Starting from the root, you have to collect all the coins such that the coins at a node can only be collected if the coins of its ancestors have been already collected.

+ +

Coins at nodei can be collected in one of the following ways:

+ + + +

Return the maximum points you can get after collecting the coins from all the tree nodes.

+ +

 

+

Example 1:

+ +
+Input: edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5
+Output: 11                        
+Explanation: 
+Collect all the coins from node 0 using the first way. Total points = 10 - 5 = 5.
+Collect all the coins from node 1 using the first way. Total points = 5 + (10 - 5) = 10.
+Collect all the coins from node 2 using the second way so coins left at node 3 will be floor(3 / 2) = 1. Total points = 10 + floor(3 / 2) = 11.
+Collect all the coins from node 3 using the second way. Total points = 11 + floor(1 / 2) = 11.
+It can be shown that the maximum points we can get after collecting coins from all the nodes is 11. 
+
+ +

Example 2:

+ + +
+Input: edges = [[0,1],[0,2]], coins = [8,4,4], k = 0
+Output: 16
+Explanation: 
+Coins will be collected from all the nodes using the first way. Therefore, total points = (8 - 0) + (4 - 0) + (4 - 0) = 16.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/images/ex1-copy.png b/solution/2900-2999/2920.Maximum Points After Collecting Coins From All Nodes/images/ex1-copy.png new file mode 100644 index 0000000000000000000000000000000000000000..da340d84e22220cf35eda5e974529d89a55b1d1d GIT binary patch literal 5602 zcmeI0cQBmoyT`R4L~n_1qen?}RtZ*(-ap*AU`ko}?y)iZR>mm#QXSSXjiAzZdq%eDEa}7EOv8NZ!D2W;g4J3!@=z#H>OM zwjk?czqF_K?Vz`y%7;XJg9xfPV-ZSKK5{}zLTFNOlWcxYm_l- zVq#IOZX$)%W7XcrSP#hZ_V12F)W_MVG6Jj0Q0L$xmOT|8pQkzHQth^Eb72?1l3Cjyk+f4^T6HIwf^@BX5Pa}Xry<*;T{}?I6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f>t?Q#*}{XD}<-8|4O7KrrdGh2G&9pqogD)*VKXvm)H&*yq0aj)Sux?Im zr>8X6VtRXfu^~!wO)l!@Qa4uhTLxBR41sQ_TbfKJ$7r^HKz&>3b$F?pH@dNs_dHmE zJ!HD+N5#kSczlQ^R0?*`1E!Q^0MyMR-J;RxKv!2+sOOON^^d_0mO)TAZ*;>R2qpE5 z?^=WFc1|MIS!O}qywI(ztn6TAW#w?#_Ko9uF-uTUQPFN02zB#Fx0;%o(>r(W3{@Oi zUtd2|U0vN{84Pvvh^nfp^G!`ngJCdWb8|BWN_|!Upl%+aA0^jYT3Q0#li>PvxNyx1 z5Y){>Lk6`cLC=BfvjPZp^YBrMSTZPsDO?9)MO>E^V5pmigDK1=m_D6`_G5NHU(XpU z1W-2*r_(T>YU+YYDwUc*`(v@#0V_mMHxCz7u#$$QWK;H(pq;wCgU$+IofS@~o0oe^ zu!-o{v16il6?SxVjG~>U?A4)e=IFK^+eZGsrZt!Tu_85|w+ z`)n!BZlWE|NuEafId#hy4LCH6Q}al#k+1wR_#XXz5AnUaN5i4z2KqI1^NU*KmqEfH zWXwW}J>*REYQ7ntgU@SgYs=vC3kwS$IQdy>>BrPf)GPyXOd`oDvgIOOH1f=&&;lxE zVEz`PdKhN5+8}=8-*_GGXQ`VBAWby#q_?8d2ukgs z))b0`q1vER=F=`4iRyWH9krB7N=o{j${MZC-$&@1)Gb&32b2vNLWt>##Q*>R07*qo IM6N<$g6_Pi(*OVf literal 0 HcmV?d00001 diff --git a/solution/CONTEST_README.md b/solution/CONTEST_README.md index 992d7230dd9a0..1e35f12bb5c89 100644 --- a/solution/CONTEST_README.md +++ b/solution/CONTEST_README.md @@ -22,6 +22,20 @@ ## 往期竞赛 +#### 第 369 场周赛(2023-10-29 10:30, 90 分钟) 参赛人数 4121 + +- [2917. 找出数组中的 K-or 值](/solution/2900-2999/2917.Find%20the%20K-or%20of%20an%20Array/README.md) +- [2918. 数组的最小相等和](/solution/2900-2999/2918.Minimum%20Equal%20Sum%20of%20Two%20Arrays%20After%20Replacing%20Zeros/README.md) +- [2919. 使数组变美的最小增量运算数](/solution/2900-2999/2919.Minimum%20Increment%20Operations%20to%20Make%20Array%20Beautiful/README.md) +- [2920. 收集所有金币可获得的最大积分](/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/README.md) + +#### 第 116 场双周赛(2023-10-28 22:30, 90 分钟) 参赛人数 2904 + +- [2913. 子数组不同元素数目的平方和 I](/solution/2900-2999/2913.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20I/README.md) +- [2914. 使二进制字符串变美丽的最少修改次数](/solution/2900-2999/2914.Minimum%20Number%20of%20Changes%20to%20Make%20Binary%20String%20Beautiful/README.md) +- [2915. 和为目标值的最长子序列的长度](/solution/2900-2999/2915.Length%20of%20the%20Longest%20Subsequence%20That%20Sums%20to%20Target/README.md) +- [2916. 子数组不同元素数目的平方和 II](/solution/2900-2999/2916.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20II/README.md) + #### 第 368 场周赛(2023-10-22 10:30, 90 分钟) 参赛人数 5002 - [2908. 元素和最小的山形三元组 I](/solution/2900-2999/2908.Minimum%20Sum%20of%20Mountain%20Triplets%20I/README.md) diff --git a/solution/CONTEST_README_EN.md b/solution/CONTEST_README_EN.md index 6274df1765a81..4eba855bbc6b9 100644 --- a/solution/CONTEST_README_EN.md +++ b/solution/CONTEST_README_EN.md @@ -25,6 +25,20 @@ Get your rating changes right after the completion of LeetCode contests, https:/ ## Past Contests +#### Weekly Contest 369 + +- [2917. Find the K-or of an Array](/solution/2900-2999/2917.Find%20the%20K-or%20of%20an%20Array/README_EN.md) +- [2918. Minimum Equal Sum of Two Arrays After Replacing Zeros](/solution/2900-2999/2918.Minimum%20Equal%20Sum%20of%20Two%20Arrays%20After%20Replacing%20Zeros/README_EN.md) +- [2919. Minimum Increment Operations to Make Array Beautiful](/solution/2900-2999/2919.Minimum%20Increment%20Operations%20to%20Make%20Array%20Beautiful/README_EN.md) +- [2920. Maximum Points After Collecting Coins From All Nodes](/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/README_EN.md) + +#### Biweekly Contest 116 + +- [2913. Subarrays Distinct Element Sum of Squares I](/solution/2900-2999/2913.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20I/README_EN.md) +- [2914. Minimum Number of Changes to Make Binary String Beautiful](/solution/2900-2999/2914.Minimum%20Number%20of%20Changes%20to%20Make%20Binary%20String%20Beautiful/README_EN.md) +- [2915. Length of the Longest Subsequence That Sums to Target](/solution/2900-2999/2915.Length%20of%20the%20Longest%20Subsequence%20That%20Sums%20to%20Target/README_EN.md) +- [2916. Subarrays Distinct Element Sum of Squares II](/solution/2900-2999/2916.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20II/README_EN.md) + #### Weekly Contest 368 - [2908. Minimum Sum of Mountain Triplets I](/solution/2900-2999/2908.Minimum%20Sum%20of%20Mountain%20Triplets%20I/README_EN.md) diff --git a/solution/README.md b/solution/README.md index dabb27a2dfecc..e79a603e62519 100644 --- a/solution/README.md +++ b/solution/README.md @@ -2923,6 +2923,14 @@ | 2910 | [合法分组的最少组数](/solution/2900-2999/2910.Minimum%20Number%20of%20Groups%20to%20Create%20a%20Valid%20Assignment/README.md) | `贪心`,`数组`,`哈希表` | 中等 | 第 368 场周赛 | | 2911 | [得到 K 个半回文串的最少修改次数](/solution/2900-2999/2911.Minimum%20Changes%20to%20Make%20K%20Semi-palindromes/README.md) | `双指针`,`字符串`,`动态规划` | 困难 | 第 368 场周赛 | | 2912 | [在网格上移动到目的地的方法数](/solution/2900-2999/2912.Number%20of%20Ways%20to%20Reach%20Destination%20in%20the%20Grid/README.md) | | 困难 | 🔒 | +| 2913 | [子数组不同元素数目的平方和 I](/solution/2900-2999/2913.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20I/README.md) | | 简单 | 第 116 场双周赛 | +| 2914 | [使二进制字符串变美丽的最少修改次数](/solution/2900-2999/2914.Minimum%20Number%20of%20Changes%20to%20Make%20Binary%20String%20Beautiful/README.md) | | 中等 | 第 116 场双周赛 | +| 2915 | [和为目标值的最长子序列的长度](/solution/2900-2999/2915.Length%20of%20the%20Longest%20Subsequence%20That%20Sums%20to%20Target/README.md) | | 中等 | 第 116 场双周赛 | +| 2916 | [子数组不同元素数目的平方和 II](/solution/2900-2999/2916.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20II/README.md) | | 困难 | 第 116 场双周赛 | +| 2917 | [找出数组中的 K-or 值](/solution/2900-2999/2917.Find%20the%20K-or%20of%20an%20Array/README.md) | | 简单 | 第 369 场周赛 | +| 2918 | [数组的最小相等和](/solution/2900-2999/2918.Minimum%20Equal%20Sum%20of%20Two%20Arrays%20After%20Replacing%20Zeros/README.md) | | 中等 | 第 369 场周赛 | +| 2919 | [使数组变美的最小增量运算数](/solution/2900-2999/2919.Minimum%20Increment%20Operations%20to%20Make%20Array%20Beautiful/README.md) | | 中等 | 第 369 场周赛 | +| 2920 | [收集所有金币可获得的最大积分](/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/README.md) | | 困难 | 第 369 场周赛 | ## 版权 diff --git a/solution/README_EN.md b/solution/README_EN.md index 28238034c5418..3f01369883802 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -2921,6 +2921,14 @@ Press Control + F(or Command + F on | 2910 | [Minimum Number of Groups to Create a Valid Assignment](/solution/2900-2999/2910.Minimum%20Number%20of%20Groups%20to%20Create%20a%20Valid%20Assignment/README_EN.md) | `Greedy`,`Array`,`Hash Table` | Medium | Weekly Contest 368 | | 2911 | [Minimum Changes to Make K Semi-palindromes](/solution/2900-2999/2911.Minimum%20Changes%20to%20Make%20K%20Semi-palindromes/README_EN.md) | `Two Pointers`,`String`,`Dynamic Programming` | Hard | Weekly Contest 368 | | 2912 | [Number of Ways to Reach Destination in the Grid](/solution/2900-2999/2912.Number%20of%20Ways%20to%20Reach%20Destination%20in%20the%20Grid/README_EN.md) | | Hard | 🔒 | +| 2913 | [Subarrays Distinct Element Sum of Squares I](/solution/2900-2999/2913.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20I/README_EN.md) | | Easy | Biweekly Contest 116 | +| 2914 | [Minimum Number of Changes to Make Binary String Beautiful](/solution/2900-2999/2914.Minimum%20Number%20of%20Changes%20to%20Make%20Binary%20String%20Beautiful/README_EN.md) | | Medium | Biweekly Contest 116 | +| 2915 | [Length of the Longest Subsequence That Sums to Target](/solution/2900-2999/2915.Length%20of%20the%20Longest%20Subsequence%20That%20Sums%20to%20Target/README_EN.md) | | Medium | Biweekly Contest 116 | +| 2916 | [Subarrays Distinct Element Sum of Squares II](/solution/2900-2999/2916.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20II/README_EN.md) | | Hard | Biweekly Contest 116 | +| 2917 | [Find the K-or of an Array](/solution/2900-2999/2917.Find%20the%20K-or%20of%20an%20Array/README_EN.md) | | Easy | Weekly Contest 369 | +| 2918 | [Minimum Equal Sum of Two Arrays After Replacing Zeros](/solution/2900-2999/2918.Minimum%20Equal%20Sum%20of%20Two%20Arrays%20After%20Replacing%20Zeros/README_EN.md) | | Medium | Weekly Contest 369 | +| 2919 | [Minimum Increment Operations to Make Array Beautiful](/solution/2900-2999/2919.Minimum%20Increment%20Operations%20to%20Make%20Array%20Beautiful/README_EN.md) | | Medium | Weekly Contest 369 | +| 2920 | [Maximum Points After Collecting Coins From All Nodes](/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/README_EN.md) | | Hard | Weekly Contest 369 | ## Copyright diff --git a/solution/summary.md b/solution/summary.md index 6c530673acf71..104a5e9ad401c 100644 --- a/solution/summary.md +++ b/solution/summary.md @@ -2970,3 +2970,11 @@ - [2910.合法分组的最少组数](/solution/2900-2999/2910.Minimum%20Number%20of%20Groups%20to%20Create%20a%20Valid%20Assignment/README.md) - [2911.得到 K 个半回文串的最少修改次数](/solution/2900-2999/2911.Minimum%20Changes%20to%20Make%20K%20Semi-palindromes/README.md) - [2912.在网格上移动到目的地的方法数](/solution/2900-2999/2912.Number%20of%20Ways%20to%20Reach%20Destination%20in%20the%20Grid/README.md) + - [2913.子数组不同元素数目的平方和 I](/solution/2900-2999/2913.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20I/README.md) + - [2914.使二进制字符串变美丽的最少修改次数](/solution/2900-2999/2914.Minimum%20Number%20of%20Changes%20to%20Make%20Binary%20String%20Beautiful/README.md) + - [2915.和为目标值的最长子序列的长度](/solution/2900-2999/2915.Length%20of%20the%20Longest%20Subsequence%20That%20Sums%20to%20Target/README.md) + - [2916.子数组不同元素数目的平方和 II](/solution/2900-2999/2916.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20II/README.md) + - [2917.找出数组中的 K-or 值](/solution/2900-2999/2917.Find%20the%20K-or%20of%20an%20Array/README.md) + - [2918.数组的最小相等和](/solution/2900-2999/2918.Minimum%20Equal%20Sum%20of%20Two%20Arrays%20After%20Replacing%20Zeros/README.md) + - [2919.使数组变美的最小增量运算数](/solution/2900-2999/2919.Minimum%20Increment%20Operations%20to%20Make%20Array%20Beautiful/README.md) + - [2920.收集所有金币可获得的最大积分](/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/README.md) diff --git a/solution/summary_en.md b/solution/summary_en.md index c86edb99ce777..ebdf1445df18f 100644 --- a/solution/summary_en.md +++ b/solution/summary_en.md @@ -2970,3 +2970,11 @@ - [2910.Minimum Number of Groups to Create a Valid Assignment](/solution/2900-2999/2910.Minimum%20Number%20of%20Groups%20to%20Create%20a%20Valid%20Assignment/README_EN.md) - [2911.Minimum Changes to Make K Semi-palindromes](/solution/2900-2999/2911.Minimum%20Changes%20to%20Make%20K%20Semi-palindromes/README_EN.md) - [2912.Number of Ways to Reach Destination in the Grid](/solution/2900-2999/2912.Number%20of%20Ways%20to%20Reach%20Destination%20in%20the%20Grid/README_EN.md) + - [2913.Subarrays Distinct Element Sum of Squares I](/solution/2900-2999/2913.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20I/README_EN.md) + - [2914.Minimum Number of Changes to Make Binary String Beautiful](/solution/2900-2999/2914.Minimum%20Number%20of%20Changes%20to%20Make%20Binary%20String%20Beautiful/README_EN.md) + - [2915.Length of the Longest Subsequence That Sums to Target](/solution/2900-2999/2915.Length%20of%20the%20Longest%20Subsequence%20That%20Sums%20to%20Target/README_EN.md) + - [2916.Subarrays Distinct Element Sum of Squares II](/solution/2900-2999/2916.Subarrays%20Distinct%20Element%20Sum%20of%20Squares%20II/README_EN.md) + - [2917.Find the K-or of an Array](/solution/2900-2999/2917.Find%20the%20K-or%20of%20an%20Array/README_EN.md) + - [2918.Minimum Equal Sum of Two Arrays After Replacing Zeros](/solution/2900-2999/2918.Minimum%20Equal%20Sum%20of%20Two%20Arrays%20After%20Replacing%20Zeros/README_EN.md) + - [2919.Minimum Increment Operations to Make Array Beautiful](/solution/2900-2999/2919.Minimum%20Increment%20Operations%20to%20Make%20Array%20Beautiful/README_EN.md) + - [2920.Maximum Points After Collecting Coins From All Nodes](/solution/2900-2999/2920.Maximum%20Points%20After%20Collecting%20Coins%20From%20All%20Nodes/README_EN.md)