From 92b3e8bce7dcc65dc0aa91deaf776c23a50a80b7 Mon Sep 17 00:00:00 2001 From: yanglbme Date: Fri, 10 Jan 2025 09:34:12 +0800 Subject: [PATCH] feat: update lc problems --- .../3019.Number of Changing Keys/README.md | 2 +- .../3019.Number of Changing Keys/README_EN.md | 2 +- .../README.md | 104 ++++++++++++++++++ .../README_EN.md | 104 ++++++++++++++++++ solution/README.md | 1 + solution/README_EN.md | 1 + 6 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 solution/3400-3499/3416.Subsequences with a Unique Middle Mode II/README.md create mode 100644 solution/3400-3499/3416.Subsequences with a Unique Middle Mode II/README_EN.md diff --git a/solution/3000-3099/3019.Number of Changing Keys/README.md b/solution/3000-3099/3019.Number of Changing Keys/README.md index 065a79f073985..f4185f581cf1f 100644 --- a/solution/3000-3099/3019.Number of Changing Keys/README.md +++ b/solution/3000-3099/3019.Number of Changing Keys/README.md @@ -31,7 +31,7 @@ tags:
 输入:s = "aAbBcC"
 输出:2
-解释:
+解释: 
 从 s[0] = 'a' 到 s[1] = 'A',不存在按键变更,因为不计入 caps lock 或 shift 。
 从 s[1] = 'A' 到 s[2] = 'b',按键变更。
 从 s[2] = 'b' 到 s[3] = 'B',不存在按键变更,因为不计入 caps lock 或 shift 。
diff --git a/solution/3000-3099/3019.Number of Changing Keys/README_EN.md b/solution/3000-3099/3019.Number of Changing Keys/README_EN.md
index 40d4ccdb81352..dab3135859c5e 100644
--- a/solution/3000-3099/3019.Number of Changing Keys/README_EN.md	
+++ b/solution/3000-3099/3019.Number of Changing Keys/README_EN.md	
@@ -30,7 +30,7 @@ tags:
 
 Input: s = "aAbBcC"
 Output: 2
-Explanation:
+Explanation: 
 From s[0] = 'a' to s[1] = 'A', there is no change of key as caps lock or shift is not counted.
 From s[1] = 'A' to s[2] = 'b', there is a change of key.
 From s[2] = 'b' to s[3] = 'B', there is no change of key as caps lock or shift is not counted.
diff --git a/solution/3400-3499/3416.Subsequences with a Unique Middle Mode II/README.md b/solution/3400-3499/3416.Subsequences with a Unique Middle Mode II/README.md
new file mode 100644
index 0000000000000..401c3920d8ce7
--- /dev/null
+++ b/solution/3400-3499/3416.Subsequences with a Unique Middle Mode II/README.md	
@@ -0,0 +1,104 @@
+---
+comments: true
+difficulty: 困难
+edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3416.Subsequences%20with%20a%20Unique%20Middle%20Mode%20II/README.md
+---
+
+
+
+# [3416. Subsequences with a Unique Middle Mode II 🔒](https://leetcode.cn/problems/subsequences-with-a-unique-middle-mode-ii)
+
+[English Version](/solution/3400-3499/3416.Subsequences%20with%20a%20Unique%20Middle%20Mode%20II/README_EN.md)
+
+## 题目描述
+
+
+
+

Given an integer array nums, find the number of subsequences of size 5 of nums with a unique middle mode.

+ +

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

+ +

A mode of a sequence of numbers is defined as the element that appears the maximum number of times in the sequence.

+ +

A sequence of numbers contains a unique mode if it has only one mode.

+ +

A sequence of numbers seq of size 5 contains a unique middle mode if the middle element (seq[2]) is a unique mode.

+ +

 

+

Example 1:

+ +

Input: nums = [1,1,1,1,1,1]

+ +

Output: 6

+ +

Explanation:

+ +

[1, 1, 1, 1, 1] is the only subsequence of size 5 that can be formed from this list, and it has a unique middle mode of 1.

+ +

Example 2:

+ +

Input: nums = [1,2,2,3,3,4]

+ +

Output: 4

+ +

Explanation:

+ +

[1, 2, 2, 3, 4] and [1, 2, 3, 3, 4] have unique middle modes because the number at index 2 has the greatest frequency in the subsequence. [1, 2, 2, 3, 3] does not have a unique middle mode because 2 and 3 both appear twice in the subsequence.

+ +

Example 3:

+ +

Input: nums = [0,1,2,3,4,5,6,7,8]

+ +

Output: 0

+ +

Explanation:

+ +

There does not exist a subsequence of length 5 with a unique middle mode.

+ +

 

+

Constraints:

+ +
    +
  • 5 <= nums.length <= 105
  • +
  • -109 <= nums[i] <= 109
  • +
+ + + +## 解法 + + + +### 方法一 + + + +#### Python3 + +```python + +``` + +#### Java + +```java + +``` + +#### C++ + +```cpp + +``` + +#### Go + +```go + +``` + + + + + + diff --git a/solution/3400-3499/3416.Subsequences with a Unique Middle Mode II/README_EN.md b/solution/3400-3499/3416.Subsequences with a Unique Middle Mode II/README_EN.md new file mode 100644 index 0000000000000..265e95e1ffc0e --- /dev/null +++ b/solution/3400-3499/3416.Subsequences with a Unique Middle Mode II/README_EN.md @@ -0,0 +1,104 @@ +--- +comments: true +difficulty: Hard +edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3416.Subsequences%20with%20a%20Unique%20Middle%20Mode%20II/README_EN.md +--- + + + +# [3416. Subsequences with a Unique Middle Mode II 🔒](https://leetcode.com/problems/subsequences-with-a-unique-middle-mode-ii) + +[中文文档](/solution/3400-3499/3416.Subsequences%20with%20a%20Unique%20Middle%20Mode%20II/README.md) + +## Description + + + +

Given an integer array nums, find the number of subsequences of size 5 of nums with a unique middle mode.

+ +

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

+ +

A mode of a sequence of numbers is defined as the element that appears the maximum number of times in the sequence.

+ +

A sequence of numbers contains a unique mode if it has only one mode.

+ +

A sequence of numbers seq of size 5 contains a unique middle mode if the middle element (seq[2]) is a unique mode.

+ +

 

+

Example 1:

+ +

Input: nums = [1,1,1,1,1,1]

+ +

Output: 6

+ +

Explanation:

+ +

[1, 1, 1, 1, 1] is the only subsequence of size 5 that can be formed from this list, and it has a unique middle mode of 1.

+ +

Example 2:

+ +

Input: nums = [1,2,2,3,3,4]

+ +

Output: 4

+ +

Explanation:

+ +

[1, 2, 2, 3, 4] and [1, 2, 3, 3, 4] have unique middle modes because the number at index 2 has the greatest frequency in the subsequence. [1, 2, 2, 3, 3] does not have a unique middle mode because 2 and 3 both appear twice in the subsequence.

+ +

Example 3:

+ +

Input: nums = [0,1,2,3,4,5,6,7,8]

+ +

Output: 0

+ +

Explanation:

+ +

There does not exist a subsequence of length 5 with a unique middle mode.

+ +

 

+

Constraints:

+ +
    +
  • 5 <= nums.length <= 105
  • +
  • -109 <= nums[i] <= 109
  • +
+ + + +## Solutions + + + +### Solution 1 + + + +#### Python3 + +```python + +``` + +#### Java + +```java + +``` + +#### C++ + +```cpp + +``` + +#### Go + +```go + +``` + + + + + + diff --git a/solution/README.md b/solution/README.md index e4f959a807387..62cb9e9a55bcc 100644 --- a/solution/README.md +++ b/solution/README.md @@ -3426,6 +3426,7 @@ | 3413 | [收集连续 K 个袋子可以获得的最多硬币数量](/solution/3400-3499/3413.Maximum%20Coins%20From%20K%20Consecutive%20Bags/README.md) | | 中等 | 第 431 场周赛 | | 3414 | [不重叠区间的最大得分](/solution/3400-3499/3414.Maximum%20Score%20of%20Non-overlapping%20Intervals/README.md) | | 困难 | 第 431 场周赛 | | 3415 | [Find Products with Three Consecutive Digits](/solution/3400-3499/3415.Find%20Products%20with%20Three%20Consecutive%20Digits/README.md) | | 简单 | 🔒 | +| 3416 | [Subsequences with a Unique Middle Mode II](/solution/3400-3499/3416.Subsequences%20with%20a%20Unique%20Middle%20Mode%20II/README.md) | | 困难 | 🔒 | ## 版权 diff --git a/solution/README_EN.md b/solution/README_EN.md index 13c7c285e4134..91fa8215b0265 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -3424,6 +3424,7 @@ Press Control + F(or Command + F on | 3413 | [Maximum Coins From K Consecutive Bags](/solution/3400-3499/3413.Maximum%20Coins%20From%20K%20Consecutive%20Bags/README_EN.md) | | Medium | Weekly Contest 431 | | 3414 | [Maximum Score of Non-overlapping Intervals](/solution/3400-3499/3414.Maximum%20Score%20of%20Non-overlapping%20Intervals/README_EN.md) | | Hard | Weekly Contest 431 | | 3415 | [Find Products with Three Consecutive Digits](/solution/3400-3499/3415.Find%20Products%20with%20Three%20Consecutive%20Digits/README_EN.md) | | Easy | 🔒 | +| 3416 | [Subsequences with a Unique Middle Mode II](/solution/3400-3499/3416.Subsequences%20with%20a%20Unique%20Middle%20Mode%20II/README_EN.md) | | Hard | 🔒 | ## Copyright