diff --git a/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README.md b/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README.md new file mode 100644 index 0000000000000..435235fcb01c4 --- /dev/null +++ b/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README.md @@ -0,0 +1,91 @@ +# [2956. 找到两个数组中的公共元素](https://leetcode.cn/problems/find-common-elements-between-two-arrays) + +[English Version](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README_EN.md) + +## 题目描述 + + + +

给你两个下标从 0 开始的整数数组 nums1 和 nums2 ,它们分别含有 n 和 m 个元素。

+ +

请你计算以下两个数值:

+ + + +

请你返回一个长度为 2 的整数数组 answer ,按顺序 分别为以上两个数值。

+ +

 

+ +

示例 1:

+ +
+输入:nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]
+输出:[3,4]
+解释:分别计算两个数值:
+- nums1 中下标为 1 ,2 和 3 的元素在 nums2 中至少出现了一次,所以第一个值为 3 。
+- nums2 中下标为 0 ,1 ,3 和 4 的元素在 nums1 中至少出现了一次,所以第二个值为 4 。
+
+ +

示例 2:

+ +
+输入:nums1 = [3,4,2,3], nums2 = [1,5]
+输出:[0,0]
+解释:两个数组中没有公共元素,所以两个值都为 0 。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README_EN.md b/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README_EN.md new file mode 100644 index 0000000000000..b11c5c9423731 --- /dev/null +++ b/solution/2900-2999/2956.Find Common Elements Between Two Arrays/README_EN.md @@ -0,0 +1,81 @@ +# [2956. Find Common Elements Between Two Arrays](https://leetcode.com/problems/find-common-elements-between-two-arrays) + +[中文文档](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README.md) + +## Description + +

You are given two 0-indexed integer arrays nums1 and nums2 of sizes n and m, respectively.

+ +

Consider calculating the following values:

+ + + +

Return an integer array answer of size 2 containing the two values in the above order.

+ +

 

+

Example 1:

+ +
+Input: nums1 = [4,3,2,3,1], nums2 = [2,2,5,2,3,6]
+Output: [3,4]
+Explanation: We calculate the values as follows:
+- The elements at indices 1, 2, and 3 in nums1 occur at least once in nums2. So the first value is 3.
+- The elements at indices 0, 1, 3, and 4 in nums2 occur at least once in nums1. So the second value is 4.
+
+ +

Example 2:

+ +
+Input: nums1 = [3,4,2,3], nums2 = [1,5]
+Output: [0,0]
+Explanation: There are no common elements between the two arrays, so the two values will be 0.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README.md b/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README.md new file mode 100644 index 0000000000000..9accec35bc8dd --- /dev/null +++ b/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README.md @@ -0,0 +1,94 @@ +# [2957. 消除相邻近似相等字符](https://leetcode.cn/problems/remove-adjacent-almost-equal-characters) + +[English Version](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README_EN.md) + +## 题目描述 + + + +

给你一个下标从 0 开始的字符串 word 。

+ +

一次操作中,你可以选择 word 中任意一个下标 i ,将 word[i] 修改成任意一个小写英文字母。

+ +

请你返回消除 word 中所有相邻 近似相等 字符的 最少 操作次数。

+ +

两个字符 a 和 b 如果满足 a == b 或者 a 和 b 在字母表中是相邻的,那么我们称它们是 近似相等 字符。

+ +

 

+ +

示例 1:

+ +
+输入:word = "aaaaa"
+输出:2
+解释:我们将 word 变为 "acaca" ,该字符串没有相邻近似相等字符。
+消除 word 中所有相邻近似相等字符最少需要 2 次操作。
+
+ +

示例 2:

+ +
+输入:word = "abddez"
+输出:2
+解释:我们将 word 变为 "ybdoez" ,该字符串没有相邻近似相等字符。
+消除 word 中所有相邻近似相等字符最少需要 2 次操作。
+ +

示例 3:

+ +
+输入:word = "zyxyxyz"
+输出:3
+解释:我们将 word 变为 "zaxaxaz" ,该字符串没有相邻近似相等字符。
+消除 word 中所有相邻近似相等字符最少需要 3 次操作
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README_EN.md b/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README_EN.md new file mode 100644 index 0000000000000..4dd3436509c40 --- /dev/null +++ b/solution/2900-2999/2957.Remove Adjacent Almost-Equal Characters/README_EN.md @@ -0,0 +1,84 @@ +# [2957. Remove Adjacent Almost-Equal Characters](https://leetcode.com/problems/remove-adjacent-almost-equal-characters) + +[中文文档](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README.md) + +## Description + +

You are given a 0-indexed string word.

+ +

In one operation, you can pick any index i of word and change word[i] to any lowercase English letter.

+ +

Return the minimum number of operations needed to remove all adjacent almost-equal characters from word.

+ +

Two characters a and b are almost-equal if a == b or a and b are adjacent in the alphabet.

+ +

 

+

Example 1:

+ +
+Input: word = "aaaaa"
+Output: 2
+Explanation: We can change word into "acaca" which does not have any adjacent almost-equal characters.
+It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.
+
+ +

Example 2:

+ +
+Input: word = "abddez"
+Output: 2
+Explanation: We can change word into "ybdoez" which does not have any adjacent almost-equal characters.
+It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 2.
+ +

Example 3:

+ +
+Input: word = "zyxyxyz"
+Output: 3
+Explanation: We can change word into "zaxaxaz" which does not have any adjacent almost-equal characters. 
+It can be shown that the minimum number of operations needed to remove all adjacent almost-equal characters from word is 3.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README.md b/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README.md new file mode 100644 index 0000000000000..b8f52ded28f1f --- /dev/null +++ b/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README.md @@ -0,0 +1,98 @@ +# [2958. 最多 K 个重复元素的最长子数组](https://leetcode.cn/problems/length-of-longest-subarray-with-at-most-k-frequency) + +[English Version](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README_EN.md) + +## 题目描述 + + + +

给你一个整数数组 nums 和一个整数 k 。

+ +

一个元素 x 在数组中的 频率 指的是它在数组中的出现次数。

+ +

如果一个数组中所有元素的频率都 小于等于 k ,那么我们称这个数组是  数组。

+ +

请你返回 nums 中 最长好 子数组的长度。

+ +

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

+ +

 

+ +

示例 1:

+ +
+输入:nums = [1,2,3,1,2,3,1,2], k = 2
+输出:6
+解释:最长好子数组是 [1,2,3,1,2,3] ,值 1 ,2 和 3 在子数组中的频率都没有超过 k = 2 。[2,3,1,2,3,1] 和 [3,1,2,3,1,2] 也是好子数组。
+最长好子数组的长度为 6 。
+
+ +

示例 2:

+ +
+输入:nums = [1,2,1,2,1,2,1,2], k = 1
+输出:2
+解释:最长好子数组是 [1,2] ,值 1 和 2 在子数组中的频率都没有超过 k = 1 。[2,1] 也是好子数组。
+最长好子数组的长度为 2 。
+
+ +

示例 3:

+ +
+输入:nums = [5,5,5,5,5,5,5], k = 4
+输出:4
+解释:最长好子数组是 [5,5,5,5] ,值 5 在子数组中的频率没有超过 k = 4 。
+最长好子数组的长度为 4 。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README_EN.md b/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README_EN.md new file mode 100644 index 0000000000000..b5eec0be8447a --- /dev/null +++ b/solution/2900-2999/2958.Length of Longest Subarray With at Most K Frequency/README_EN.md @@ -0,0 +1,88 @@ +# [2958. Length of Longest Subarray With at Most K Frequency](https://leetcode.com/problems/length-of-longest-subarray-with-at-most-k-frequency) + +[中文文档](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README.md) + +## Description + +

You are given an integer array nums and an integer k.

+ +

The frequency of an element x is the number of times it occurs in an array.

+ +

An array is called good if the frequency of each element in this array is less than or equal to k.

+ +

Return the length of the longest good subarray of nums.

+ +

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

+ +

 

+

Example 1:

+ +
+Input: nums = [1,2,3,1,2,3,1,2], k = 2
+Output: 6
+Explanation: The longest possible good subarray is [1,2,3,1,2,3] since the values 1, 2, and 3 occur at most twice in this subarray. Note that the subarrays [2,3,1,2,3,1] and [3,1,2,3,1,2] are also good.
+It can be shown that there are no good subarrays with length more than 6.
+
+ +

Example 2:

+ +
+Input: nums = [1,2,1,2,1,2,1,2], k = 1
+Output: 2
+Explanation: The longest possible good subarray is [1,2] since the values 1 and 2 occur at most once in this subarray. Note that the subarray [2,1] is also good.
+It can be shown that there are no good subarrays with length more than 2.
+
+ +

Example 3:

+ +
+Input: nums = [5,5,5,5,5,5,5], k = 4
+Output: 4
+Explanation: The longest possible good subarray is [5,5,5,5] since the value 5 occurs 4 times in this subarray.
+It can be shown that there are no good subarrays with length more than 4.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/README.md b/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/README.md new file mode 100644 index 0000000000000..8c84013dd921f --- /dev/null +++ b/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/README.md @@ -0,0 +1,125 @@ +# [2959. 关闭分部的可行集合数目](https://leetcode.cn/problems/number-of-possible-sets-of-closing-branches) + +[English Version](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README_EN.md) + +## 题目描述 + + + +

一个公司在全国有 n 个分部,它们之间有的有道路连接。一开始,所有分部通过这些道路两两之间互相可以到达。

+ +

公司意识到在分部之间旅行花费了太多时间,所以它们决定关闭一些分部(也可能不关闭任何分部),同时保证剩下的分部之间两两互相可以到达且最远距离不超过 maxDistance 。

+ +

两个分部之间的 距离 是通过道路长度之和的 最小值 。

+ +

给你整数 n ,maxDistance 和下标从 0 开始的二维整数数组 roads ,其中 roads[i] = [ui, vi, wi] 表示一条从 ui 到 vi 长度为 wi的 无向 道路。

+ +

请你返回关闭分部的可行方案数目,满足每个方案里剩余分部之间的最远距离不超过 maxDistance

+ +

注意,关闭一个分部后,与之相连的所有道路不可通行。

+ +

注意,两个分部之间可能会有多条道路。

+ +

 

+ +

示例 1:

+ +

+ +
+输入:n = 3, maxDistance = 5, roads = [[0,1,2],[1,2,10],[0,2,10]]
+输出:5
+解释:可行的关闭分部方案有:
+- 关闭分部集合 [2] ,剩余分部为 [0,1] ,它们之间的距离为 2 。
+- 关闭分部集合 [0,1] ,剩余分部为 [2] 。
+- 关闭分部集合 [1,2] ,剩余分部为 [0] 。
+- 关闭分部集合 [0,2] ,剩余分部为 [1] 。
+- 关闭分部集合 [0,1,2] ,关闭后没有剩余分部。
+总共有 5 种可行的关闭方案。
+
+ +

示例 2:

+ +

+ +
+输入:n = 3, maxDistance = 5, roads = [[0,1,20],[0,1,10],[1,2,2],[0,2,2]]
+输出:7
+解释:可行的关闭分部方案有:
+- 关闭分部集合 [] ,剩余分部为 [0,1,2] ,它们之间的最远距离为 4 。
+- 关闭分部集合 [0] ,剩余分部为 [1,2] ,它们之间的距离为 2 。
+- 关闭分部集合 [1] ,剩余分部为 [0,2] ,它们之间的距离为 2 。
+- 关闭分部集合 [0,1] ,剩余分部为 [2] 。
+- 关闭分部集合 [1,2] ,剩余分部为 [0] 。
+- 关闭分部集合 [0,2] ,剩余分部为 [1] 。
+- 关闭分部集合 [0,1,2] ,关闭后没有剩余分部。
+总共有 7 种可行的关闭方案。
+
+ +

示例 3:

+ +
+输入:n = 1, maxDistance = 10, roads = []
+输出:2
+解释:可行的关闭分部方案有:
+- 关闭分部集合 [] ,剩余分部为 [0] 。
+- 关闭分部集合 [0] ,关闭后没有剩余分部。
+总共有 2 种可行的关闭方案。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/README_EN.md b/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/README_EN.md new file mode 100644 index 0000000000000..b40dd7f6021d5 --- /dev/null +++ b/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/README_EN.md @@ -0,0 +1,111 @@ +# [2959. Number of Possible Sets of Closing Branches](https://leetcode.com/problems/number-of-possible-sets-of-closing-branches) + +[中文文档](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README.md) + +## Description + +

There is a company with n branches across the country, some of which are connected by roads. Initially, all branches are reachable from each other by traveling some roads.

+ +

The company has realized that they are spending an excessive amount of time traveling between their branches. As a result, they have decided to close down some of these branches (possibly none). However, they want to ensure that the remaining branches have a distance of at most maxDistance from each other.

+ +

The distance between two branches is the minimum total traveled length needed to reach one branch from another.

+ +

You are given integers n, maxDistance, and a 0-indexed 2D array roads, where roads[i] = [ui, vi, wi] represents the undirected road between branches ui and vi with length wi.

+ +

Return the number of possible sets of closing branches, so that any branch has a distance of at most maxDistance from any other.

+ +

Note that, after closing a branch, the company will no longer have access to any roads connected to it.

+ +

Note that, multiple roads are allowed.

+ +

 

+

Example 1:

+ +
+Input: n = 3, maxDistance = 5, roads = [[0,1,2],[1,2,10],[0,2,10]]
+Output: 5
+Explanation: The possible sets of closing branches are:
+- The set [2], after closing, active branches are [0,1] and they are reachable to each other within distance 2.
+- The set [0,1], after closing, the active branch is [2].
+- The set [1,2], after closing, the active branch is [0].
+- The set [0,2], after closing, the active branch is [1].
+- The set [0,1,2], after closing, there are no active branches.
+It can be proven, that there are only 5 possible sets of closing branches.
+
+ +

Example 2:

+ +
+Input: n = 3, maxDistance = 5, roads = [[0,1,20],[0,1,10],[1,2,2],[0,2,2]]
+Output: 7
+Explanation: The possible sets of closing branches are:
+- The set [], after closing, active branches are [0,1,2] and they are reachable to each other within distance 4.
+- The set [0], after closing, active branches are [1,2] and they are reachable to each other within distance 2.
+- The set [1], after closing, active branches are [0,2] and they are reachable to each other within distance 2.
+- The set [0,1], after closing, the active branch is [2].
+- The set [1,2], after closing, the active branch is [0].
+- The set [0,2], after closing, the active branch is [1].
+- The set [0,1,2], after closing, there are no active branches.
+It can be proven, that there are only 7 possible sets of closing branches.
+
+ +

Example 3:

+ +
+Input: n = 1, maxDistance = 10, roads = []
+Output: 2
+Explanation: The possible sets of closing branches are:
+- The set [], after closing, the active branch is [0].
+- The set [0], after closing, there are no active branches.
+It can be proven, that there are only 2 possible sets of closing branches.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/images/example11.png b/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/images/example11.png new file mode 100644 index 0000000000000..cc4baf36d6ce7 Binary files /dev/null and b/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/images/example11.png differ diff --git a/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/images/example22.png b/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/images/example22.png new file mode 100644 index 0000000000000..541c68fbe0f4d Binary files /dev/null and b/solution/2900-2999/2959.Number of Possible Sets of Closing Branches/images/example22.png differ diff --git a/solution/2900-2999/2960.Count Tested Devices After Test Operations/README.md b/solution/2900-2999/2960.Count Tested Devices After Test Operations/README.md new file mode 100644 index 0000000000000..7735b6d7f5b43 --- /dev/null +++ b/solution/2900-2999/2960.Count Tested Devices After Test Operations/README.md @@ -0,0 +1,105 @@ +# [2960. 统计已测试设备](https://leetcode.cn/problems/count-tested-devices-after-test-operations) + +[English Version](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README_EN.md) + +## 题目描述 + + + +

给你一个长度为 n 、下标从 0 开始的整数数组 batteryPercentages ,表示 n 个设备的电池百分比。

+ +

你的任务是按照顺序测试每个设备 i,执行以下测试操作:

+ + + +

返回一个整数,表示按顺序执行测试操作后 已测试设备 的数量。

+ +

 

+ +

示例 1:

+ +
+输入:batteryPercentages = [1,1,2,1,3]
+输出:3
+解释:按顺序从设备 0 开始执行测试操作:
+在设备 0 上,batteryPercentages[0] > 0 ,现在有 1 个已测试设备,batteryPercentages 变为 [1,0,1,0,2] 。
+在设备 1 上,batteryPercentages[1] == 0 ,移动到下一个设备而不进行测试。
+在设备 2 上,batteryPercentages[2] > 0 ,现在有 2 个已测试设备,batteryPercentages 变为 [1,0,1,0,1] 。
+在设备 3 上,batteryPercentages[3] == 0 ,移动到下一个设备而不进行测试。
+在设备 4 上,batteryPercentages[4] > 0 ,现在有 3 个已测试设备,batteryPercentages 保持不变。
+因此,答案是 3 。
+
+ +

示例 2:

+ +
+输入:batteryPercentages = [0,1,2]
+输出:2
+解释:按顺序从设备 0 开始执行测试操作:
+在设备 0 上,batteryPercentages[0] == 0 ,移动到下一个设备而不进行测试。
+在设备 1 上,batteryPercentages[1] > 0 ,现在有 1 个已测试设备,batteryPercentages 变为 [0,1,1] 。
+在设备 2 上,batteryPercentages[2] > 0 ,现在有 2 个已测试设备,batteryPercentages 保持不变。
+因此,答案是 2 。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2960.Count Tested Devices After Test Operations/README_EN.md b/solution/2900-2999/2960.Count Tested Devices After Test Operations/README_EN.md new file mode 100644 index 0000000000000..f407a1e3e3ef6 --- /dev/null +++ b/solution/2900-2999/2960.Count Tested Devices After Test Operations/README_EN.md @@ -0,0 +1,95 @@ +# [2960. Count Tested Devices After Test Operations](https://leetcode.com/problems/count-tested-devices-after-test-operations) + +[中文文档](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README.md) + +## Description + +

You are given a 0-indexed integer array batteryPercentages having length n, denoting the battery percentages of n 0-indexed devices.

+ +

Your task is to test each device i in order from 0 to n - 1, by performing the following test operations:

+ + + +

Return an integer denoting the number of devices that will be tested after performing the test operations in order.

+ +

 

+

Example 1:

+ +
+Input: batteryPercentages = [1,1,2,1,3]
+Output: 3
+Explanation: Performing the test operations in order starting from device 0:
+At device 0, batteryPercentages[0] > 0, so there is now 1 tested device, and batteryPercentages becomes [1,0,1,0,2].
+At device 1, batteryPercentages[1] == 0, so we move to the next device without testing.
+At device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages becomes [1,0,1,0,1].
+At device 3, batteryPercentages[3] == 0, so we move to the next device without testing.
+At device 4, batteryPercentages[4] > 0, so there are now 3 tested devices, and batteryPercentages stays the same.
+So, the answer is 3.
+
+ +

Example 2:

+ +
+Input: batteryPercentages = [0,1,2]
+Output: 2
+Explanation: Performing the test operations in order starting from device 0:
+At device 0, batteryPercentages[0] == 0, so we move to the next device without testing.
+At device 1, batteryPercentages[1] > 0, so there is now 1 tested device, and batteryPercentages becomes [0,1,1].
+At device 2, batteryPercentages[2] > 0, so there are now 2 tested devices, and batteryPercentages stays the same.
+So, the answer is 2.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2961.Double Modular Exponentiation/README.md b/solution/2900-2999/2961.Double Modular Exponentiation/README.md new file mode 100644 index 0000000000000..b5899ce2216fa --- /dev/null +++ b/solution/2900-2999/2961.Double Modular Exponentiation/README.md @@ -0,0 +1,95 @@ +# [2961. 双模幂运算](https://leetcode.cn/problems/double-modular-exponentiation) + +[English Version](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README_EN.md) + +## 题目描述 + + + +

给你一个下标从 0 开始的二维数组 variables ,其中 variables[i] = [ai, bi, ci, mi],以及一个整数 target

+ +

如果满足以下公式,则下标 i好下标

+ + + +

返回一个由 好下标 组成的数组,顺序不限

+ +

 

+ +

示例 1:

+ +
+输入:variables = [[2,3,3,10],[3,3,3,1],[6,1,1,4]], target = 2
+输出:[0,2]
+解释:对于 variables 数组中的每个下标 i :
+1) 对于下标 0 ,variables[0] = [2,3,3,10] ,(23 % 10)3 % 10 = 2 。
+2) 对于下标 1 ,variables[1] = [3,3,3,1] ,(33 % 10)3 % 1 = 0 。
+3) 对于下标 2 ,variables[2] = [6,1,1,4] ,(61 % 10)1 % 4 = 2 。
+因此,返回 [0,2] 作为答案。
+
+ +

示例 2:

+ +
+输入:variables = [[39,3,1000,1000]], target = 17
+输出:[]
+解释:对于 variables 数组中的每个下标 i :
+1) 对于下标 0 ,variables[0] = [39,3,1000,1000] ,(393 % 10)1000 % 1000 = 1 。
+因此,返回 [] 作为答案。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2961.Double Modular Exponentiation/README_EN.md b/solution/2900-2999/2961.Double Modular Exponentiation/README_EN.md new file mode 100644 index 0000000000000..1023b087ec946 --- /dev/null +++ b/solution/2900-2999/2961.Double Modular Exponentiation/README_EN.md @@ -0,0 +1,85 @@ +# [2961. Double Modular Exponentiation](https://leetcode.com/problems/double-modular-exponentiation) + +[中文文档](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README.md) + +## Description + +

You are given a 0-indexed 2D array variables where variables[i] = [ai, bi, ci, mi], and an integer target.

+ +

An index i is good if the following formula holds:

+ + + +

Return an array consisting of good indices in any order.

+ +

 

+

Example 1:

+ +
+Input: variables = [[2,3,3,10],[3,3,3,1],[6,1,1,4]], target = 2
+Output: [0,2]
+Explanation: For each index i in the variables array:
+1) For the index 0, variables[0] = [2,3,3,10], (23 % 10)3 % 10 = 2.
+2) For the index 1, variables[1] = [3,3,3,1], (33 % 10)3 % 1 = 0.
+3) For the index 2, variables[2] = [6,1,1,4], (61 % 10)1 % 4 = 2.
+Therefore we return [0,2] as the answer.
+
+ +

Example 2:

+ +
+Input: variables = [[39,3,1000,1000]], target = 17
+Output: []
+Explanation: For each index i in the variables array:
+1) For the index 0, variables[0] = [39,3,1000,1000], (393 % 10)1000 % 1000 = 1.
+Therefore we return [] as the answer.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README.md b/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README.md new file mode 100644 index 0000000000000..e468813584c23 --- /dev/null +++ b/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README.md @@ -0,0 +1,83 @@ +# [2962. 统计最大元素出现至少 K 次的子数组](https://leetcode.cn/problems/count-subarrays-where-max-element-appears-at-least-k-times) + +[English Version](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README_EN.md) + +## 题目描述 + + + +

给你一个整数数组 nums 和一个 正整数 k

+ +

请你统计有多少满足 「 nums 中的 最大 元素」至少出现 k 次的子数组,并返回满足这一条件的子数组的数目。

+ +

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

+ +

 

+ +

示例 1:

+ +
+输入:nums = [1,3,2,3,3], k = 2
+输出:6
+解释:包含元素 3 至少 2 次的子数组为:[1,3,2,3]、[1,3,2,3,3]、[3,2,3]、[3,2,3,3]、[2,3,3] 和 [3,3] 。
+
+ +

示例 2:

+ +
+输入:nums = [1,4,2,1], k = 3
+输出:0
+解释:没有子数组包含元素 4 至少 3 次。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README_EN.md b/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README_EN.md new file mode 100644 index 0000000000000..eeb556abf8bbb --- /dev/null +++ b/solution/2900-2999/2962.Count Subarrays Where Max Element Appears at Least K Times/README_EN.md @@ -0,0 +1,73 @@ +# [2962. Count Subarrays Where Max Element Appears at Least K Times](https://leetcode.com/problems/count-subarrays-where-max-element-appears-at-least-k-times) + +[中文文档](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README.md) + +## Description + +

You are given an integer array nums and a positive integer k.

+ +

Return the number of subarrays where the maximum element of nums appears at least k times in that subarray.

+ +

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

+ +

 

+

Example 1:

+ +
+Input: nums = [1,3,2,3,3], k = 2
+Output: 6
+Explanation: The subarrays that contain the element 3 at least 2 times are: [1,3,2,3], [1,3,2,3,3], [3,2,3], [3,2,3,3], [2,3,3] and [3,3].
+
+ +

Example 2:

+ +
+Input: nums = [1,4,2,1], k = 3
+Output: 0
+Explanation: No subarray contains the element 4 at least 3 times.
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2963.Count the Number of Good Partitions/README.md b/solution/2900-2999/2963.Count the Number of Good Partitions/README.md new file mode 100644 index 0000000000000..7cd9db7aa01c5 --- /dev/null +++ b/solution/2900-2999/2963.Count the Number of Good Partitions/README.md @@ -0,0 +1,92 @@ +# [2963. 统计好分割方案的数目](https://leetcode.cn/problems/count-the-number-of-good-partitions) + +[English Version](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README_EN.md) + +## 题目描述 + + + +

给你一个下标从 0 开始、由 正整数 组成的数组 nums

+ +

将数组分割成一个或多个 连续 子数组,如果不存在包含了相同数字的两个子数组,则认为是一种 好分割方案

+ +

返回 nums好分割方案数目

+ +

由于答案可能很大,请返回答案对 109 + 7 取余 的结果。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [1,2,3,4]
+输出:8
+解释:有 8 种 好分割方案 :([1], [2], [3], [4]), ([1], [2], [3,4]), ([1], [2,3], [4]), ([1], [2,3,4]), ([1,2], [3], [4]), ([1,2], [3,4]), ([1,2,3], [4]) 和 ([1,2,3,4]) 。
+
+ +

示例 2:

+ +
+输入:nums = [1,1,1,1]
+输出:1
+解释:唯一的 好分割方案 是:([1,1,1,1]) 。
+
+ +

示例 3:

+ +
+输入:nums = [1,2,1,3]
+输出:2
+解释:有 2 种 好分割方案 :([1,2,1], [3]) 和 ([1,2,1,3]) 。
+
+ +

 

+ +

提示:

+ + + +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2900-2999/2963.Count the Number of Good Partitions/README_EN.md b/solution/2900-2999/2963.Count the Number of Good Partitions/README_EN.md new file mode 100644 index 0000000000000..18d0489c8f52e --- /dev/null +++ b/solution/2900-2999/2963.Count the Number of Good Partitions/README_EN.md @@ -0,0 +1,82 @@ +# [2963. Count the Number of Good Partitions](https://leetcode.com/problems/count-the-number-of-good-partitions) + +[中文文档](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README.md) + +## Description + +

You are given a 0-indexed array nums consisting of positive integers.

+ +

A partition of an array into one or more contiguous subarrays is called good if no two subarrays contain the same number.

+ +

Return the total number of good partitions of nums.

+ +

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

+ +

 

+

Example 1:

+ +
+Input: nums = [1,2,3,4]
+Output: 8
+Explanation: The 8 possible good partitions are: ([1], [2], [3], [4]), ([1], [2], [3,4]), ([1], [2,3], [4]), ([1], [2,3,4]), ([1,2], [3], [4]), ([1,2], [3,4]), ([1,2,3], [4]), and ([1,2,3,4]).
+
+ +

Example 2:

+ +
+Input: nums = [1,1,1,1]
+Output: 1
+Explanation: The only possible good partition is: ([1,1,1,1]).
+
+ +

Example 3:

+ +
+Input: nums = [1,2,1,3]
+Output: 2
+Explanation: The 2 possible good partitions are: ([1,2,1], [3]) and ([1,2,1,3]).
+
+ +

 

+

Constraints:

+ + + +## Solutions + + + +### **Python3** + +```python + +``` + +### **Java** + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/CONTEST_README.md b/solution/CONTEST_README.md index e7f068210e689..bfb3c200c07ea 100644 --- a/solution/CONTEST_README.md +++ b/solution/CONTEST_README.md @@ -22,6 +22,20 @@ ## 往期竞赛 +#### 第 375 场周赛(2023-12-10 10:30, 90 分钟) 参赛人数 3518 + +- [2960. 统计已测试设备](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README.md) +- [2961. 双模幂运算](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README.md) +- [2962. 统计最大元素出现至少 K 次的子数组](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README.md) +- [2963. 统计好分割方案的数目](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README.md) + +#### 第 119 场双周赛(2023-12-09 22:30, 90 分钟) 参赛人数 2472 + +- [2956. 找到两个数组中的公共元素](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README.md) +- [2957. 消除相邻近似相等字符](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README.md) +- [2958. 最多 K 个重复元素的最长子数组](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README.md) +- [2959. 关闭分部的可行集合数目](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README.md) + #### 第 374 场周赛(2023-12-03 10:30, 90 分钟) 参赛人数 4053 - [2951. 找出峰值](/solution/2900-2999/2951.Find%20the%20Peaks/README.md) diff --git a/solution/CONTEST_README_EN.md b/solution/CONTEST_README_EN.md index 1c87e8db6bb59..4340ca2b4d553 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 375 + +- [2960. Count Tested Devices After Test Operations](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README_EN.md) +- [2961. Double Modular Exponentiation](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README_EN.md) +- [2962. Count Subarrays Where Max Element Appears at Least K Times](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README_EN.md) +- [2963. Count the Number of Good Partitions](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README_EN.md) + +#### Biweekly Contest 119 + +- [2956. Find Common Elements Between Two Arrays](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README_EN.md) +- [2957. Remove Adjacent Almost-Equal Characters](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README_EN.md) +- [2958. Length of Longest Subarray With at Most K Frequency](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README_EN.md) +- [2959. Number of Possible Sets of Closing Branches](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README_EN.md) + #### Weekly Contest 374 - [2951. Find the Peaks](/solution/2900-2999/2951.Find%20the%20Peaks/README_EN.md) diff --git a/solution/README.md b/solution/README.md index fc1d884069216..406985a9bcb8b 100644 --- a/solution/README.md +++ b/solution/README.md @@ -2966,6 +2966,14 @@ | 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) | | 中等 | 🔒 | +| 2956 | [找到两个数组中的公共元素](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README.md) | | 简单 | 第 119 场双周赛 | +| 2957 | [消除相邻近似相等字符](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README.md) | | 中等 | 第 119 场双周赛 | +| 2958 | [最多 K 个重复元素的最长子数组](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README.md) | | 中等 | 第 119 场双周赛 | +| 2959 | [关闭分部的可行集合数目](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README.md) | | 困难 | 第 119 场双周赛 | +| 2960 | [统计已测试设备](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README.md) | | 简单 | 第 375 场周赛 | +| 2961 | [双模幂运算](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README.md) | | 中等 | 第 375 场周赛 | +| 2962 | [统计最大元素出现至少 K 次的子数组](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README.md) | | 中等 | 第 375 场周赛 | +| 2963 | [统计好分割方案的数目](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README.md) | | 困难 | 第 375 场周赛 | ## 版权 diff --git a/solution/README_EN.md b/solution/README_EN.md index ac61bd473c8dc..770514ba030e3 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -2964,6 +2964,14 @@ Press Control + F(or Command + F on | 2953 | [Count Complete Substrings](/solution/2900-2999/2953.Count%20Complete%20Substrings/README_EN.md) | `Hash Table`,`String`,`Sliding Window` | Medium | Weekly Contest 374 | | 2954 | [Count the Number of Infection Sequences](/solution/2900-2999/2954.Count%20the%20Number%20of%20Infection%20Sequences/README_EN.md) | `Array`,`Math`,`Combinatorics` | Hard | Weekly Contest 374 | | 2955 | [Number of Same-End Substrings](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README_EN.md) | | Medium | 🔒 | +| 2956 | [Find Common Elements Between Two Arrays](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README_EN.md) | | Easy | Biweekly Contest 119 | +| 2957 | [Remove Adjacent Almost-Equal Characters](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README_EN.md) | | Medium | Biweekly Contest 119 | +| 2958 | [Length of Longest Subarray With at Most K Frequency](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README_EN.md) | | Medium | Biweekly Contest 119 | +| 2959 | [Number of Possible Sets of Closing Branches](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README_EN.md) | | Hard | Biweekly Contest 119 | +| 2960 | [Count Tested Devices After Test Operations](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README_EN.md) | | Easy | Weekly Contest 375 | +| 2961 | [Double Modular Exponentiation](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README_EN.md) | | Medium | Weekly Contest 375 | +| 2962 | [Count Subarrays Where Max Element Appears at Least K Times](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README_EN.md) | | Medium | Weekly Contest 375 | +| 2963 | [Count the Number of Good Partitions](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README_EN.md) | | Hard | Weekly Contest 375 | ## Copyright diff --git a/solution/summary.md b/solution/summary.md index 48cb7b7b590cd..d08d05f4f01ea 100644 --- a/solution/summary.md +++ b/solution/summary.md @@ -3013,3 +3013,11 @@ - [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) + - [2956.找到两个数组中的公共元素](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README.md) + - [2957.消除相邻近似相等字符](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README.md) + - [2958.最多 K 个重复元素的最长子数组](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README.md) + - [2959.关闭分部的可行集合数目](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README.md) + - [2960.统计已测试设备](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README.md) + - [2961.双模幂运算](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README.md) + - [2962.统计最大元素出现至少 K 次的子数组](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README.md) + - [2963.统计好分割方案的数目](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README.md) diff --git a/solution/summary_en.md b/solution/summary_en.md index 3fac05358fb0b..ae02a2774ab7f 100644 --- a/solution/summary_en.md +++ b/solution/summary_en.md @@ -3013,3 +3013,11 @@ - [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) + - [2956.Find Common Elements Between Two Arrays](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README_EN.md) + - [2957.Remove Adjacent Almost-Equal Characters](/solution/2900-2999/2957.Remove%20Adjacent%20Almost-Equal%20Characters/README_EN.md) + - [2958.Length of Longest Subarray With at Most K Frequency](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README_EN.md) + - [2959.Number of Possible Sets of Closing Branches](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README_EN.md) + - [2960.Count Tested Devices After Test Operations](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README_EN.md) + - [2961.Double Modular Exponentiation](/solution/2900-2999/2961.Double%20Modular%20Exponentiation/README_EN.md) + - [2962.Count Subarrays Where Max Element Appears at Least K Times](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README_EN.md) + - [2963.Count the Number of Good Partitions](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README_EN.md)