From e3c49b4a5cfc90d70edc40592679f3f0b6c02f0e Mon Sep 17 00:00:00 2001 From: yanglbme Date: Fri, 15 Nov 2024 14:15:43 +0800 Subject: [PATCH] feat: update lc problems --- .../README.md" | 6 +- .../0300-0399/0384.Shuffle an Array/README.md | 1 + .../0384.Shuffle an Array/README_EN.md | 1 + solution/0400-0499/0490.The Maze/README.md | 12 +- solution/0400-0499/0490.The Maze/README_EN.md | 4 +- .../0500-0599/0500.Keyboard Row/README.md | 43 +++-- .../0500-0599/0500.Keyboard Row/README_EN.md | 33 ++-- .../0777.Swap Adjacent in LR String/README.md | 14 +- .../0909.Snakes and Ladders/README.md | 4 +- .../1095.Find in Mountain Array/README.md | 8 +- .../1095.Find in Mountain Array/README_EN.md | 8 +- .../1257.Smallest Common Region/README.md | 36 +++-- .../README.md | 25 +-- .../README_EN.md | 2 +- .../1859.Sorting the Sentence/README_EN.md | 30 +--- .../README.md | 2 +- .../README_EN.md | 2 +- solution/2600-2699/2623.Memoize/README.md | 3 +- .../2600-2699/2694.Event Emitter/README.md | 2 +- .../2600-2699/2694.Event Emitter/README_EN.md | 2 +- .../README.md | 6 +- .../README_EN.md | 4 +- .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../3340.Check Balanced String/README.md | 2 + .../3340.Check Balanced String/README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../README.md | 2 + .../README_EN.md | 2 + .../3353.Minimum Total Operations/README.md | 149 ++++++++++++++++++ .../README_EN.md | 149 ++++++++++++++++++ .../Solution.cpp | 10 ++ .../3353.Minimum Total Operations/Solution.go | 8 + .../Solution.java | 9 ++ .../3353.Minimum Total Operations/Solution.py | 3 + .../3353.Minimum Total Operations/Solution.ts | 7 + solution/README.md | 5 +- solution/README_EN.md | 3 +- 79 files changed, 568 insertions(+), 119 deletions(-) create mode 100644 solution/3300-3399/3353.Minimum Total Operations/README.md create mode 100644 solution/3300-3399/3353.Minimum Total Operations/README_EN.md create mode 100644 solution/3300-3399/3353.Minimum Total Operations/Solution.cpp create mode 100644 solution/3300-3399/3353.Minimum Total Operations/Solution.go create mode 100644 solution/3300-3399/3353.Minimum Total Operations/Solution.java create mode 100644 solution/3300-3399/3353.Minimum Total Operations/Solution.py create mode 100644 solution/3300-3399/3353.Minimum Total Operations/Solution.ts diff --git "a/lcp/LCP 12. \345\260\217\345\274\240\345\210\267\351\242\230\350\256\241\345\210\222/README.md" "b/lcp/LCP 12. \345\260\217\345\274\240\345\210\267\351\242\230\350\256\241\345\210\222/README.md" index 5e7935ae0e3df..a2da6fe9ec4ef 100644 --- "a/lcp/LCP 12. \345\260\217\345\274\240\345\210\267\351\242\230\350\256\241\345\210\222/README.md" +++ "b/lcp/LCP 12. \345\260\217\345\274\240\345\210\267\351\242\230\350\256\241\345\210\222/README.md" @@ -224,7 +224,7 @@ class Solution { func minTime(_ time: [Int], _ m: Int) -> Int { var left = 0 var right = time.reduce(0, +) - + while left < right { let mid = (left + right) / 2 if check(mid, time, m) { @@ -235,12 +235,12 @@ class Solution { } return left } - + private func check(_ t: Int, _ time: [Int], _ m: Int) -> Bool { var sum = 0 var maxTime = 0 var days = 1 - + for x in time { sum += x maxTime = max(maxTime, x) diff --git a/solution/0300-0399/0384.Shuffle an Array/README.md b/solution/0300-0399/0384.Shuffle an Array/README.md index 6781a689ac116..b77ff02e461d0 100644 --- a/solution/0300-0399/0384.Shuffle an Array/README.md +++ b/solution/0300-0399/0384.Shuffle an Array/README.md @@ -3,6 +3,7 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/0300-0399/0384.Shuffle%20an%20Array/README.md tags: + - 设计 - 数组 - 数学 - 随机化 diff --git a/solution/0300-0399/0384.Shuffle an Array/README_EN.md b/solution/0300-0399/0384.Shuffle an Array/README_EN.md index b341bcaa9b386..95f357c5fcb5f 100644 --- a/solution/0300-0399/0384.Shuffle an Array/README_EN.md +++ b/solution/0300-0399/0384.Shuffle an Array/README_EN.md @@ -3,6 +3,7 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/0300-0399/0384.Shuffle%20an%20Array/README_EN.md tags: + - Design - Array - Math - Randomized diff --git a/solution/0400-0499/0490.The Maze/README.md b/solution/0400-0499/0490.The Maze/README.md index 982e0298eb0c6..53f4fd880dcff 100644 --- a/solution/0400-0499/0490.The Maze/README.md +++ b/solution/0400-0499/0490.The Maze/README.md @@ -28,14 +28,14 @@ tags:

你可以 假定迷宫的边缘都是墙壁(参考示例)。

-

 

+

 

示例 1:

 输入:maze = [[0,0,1,0,0],[0,0,0,0,0],[0,0,0,1,0],[1,1,0,1,1],[0,0,0,0,0]], start = [0,4], destination = [4,4]
 输出:true
-解释:一种可能的路径是 : 左 -> 下 -> 左 -> 下 -> 右 -> 下 -> 右。
+解释:一种可能的路径是 : 左 -> 下 -> 左 -> 下 -> 右 -> 下 -> 右。
 

示例 2:

@@ -53,19 +53,19 @@ tags: 输出:false -

 

+

 

提示:

diff --git a/solution/0400-0499/0490.The Maze/README_EN.md b/solution/0400-0499/0490.The Maze/README_EN.md index 856f07c599629..85f43ef399544 100644 --- a/solution/0400-0499/0490.The Maze/README_EN.md +++ b/solution/0400-0499/0490.The Maze/README_EN.md @@ -59,8 +59,8 @@ tags:
  • maze[i][j] is 0 or 1.
  • start.length == 2
  • destination.length == 2
  • -
  • 0 <= startrow, destinationrow <= m
  • -
  • 0 <= startcol, destinationcol <= n
  • +
  • 0 <= startrow, destinationrow < m
  • +
  • 0 <= startcol, destinationcol < n
  • Both the ball and the destination exist in an empty space, and they will not be in the same position initially.
  • The maze contains at least 2 empty spaces.
  • diff --git a/solution/0500-0599/0500.Keyboard Row/README.md b/solution/0500-0599/0500.Keyboard Row/README.md index d8b6ea018687d..606c7686335af 100644 --- a/solution/0500-0599/0500.Keyboard Row/README.md +++ b/solution/0500-0599/0500.Keyboard Row/README.md @@ -20,6 +20,8 @@ tags:

    给你一个字符串数组 words ,只返回可以使用在 美式键盘 同一行的字母打印出来的单词。键盘如下图所示。

    +

    请注意,字符串 不区分大小写,相同字母的大小写形式都被视为在同一行

    +

    美式键盘 中:

    diff --git a/solution/2600-2699/2623.Memoize/README.md b/solution/2600-2699/2623.Memoize/README.md index 1c6d49e34f7d7..e012a39bf4ba3 100644 --- a/solution/2600-2699/2623.Memoize/README.md +++ b/solution/2600-2699/2623.Memoize/README.md @@ -87,9 +87,10 @@ values = [[5],[]] diff --git a/solution/2600-2699/2694.Event Emitter/README.md b/solution/2600-2699/2694.Event Emitter/README.md index c21976f360c43..96404ef0f95e9 100644 --- a/solution/2600-2699/2694.Event Emitter/README.md +++ b/solution/2600-2699/2694.Event Emitter/README.md @@ -78,7 +78,7 @@ emitter.emit("firstEvent", [4, 5, 6]); // [], 没有订阅者 输入: actions = ["EventEmitter", "subscribe", "subscribe", "unsubscribe", "emit"], values = [[], ["firstEvent", "x => x + 1"], ["firstEvent", "x => x + 2"], [0], ["firstEvent", [5]]] -输出:[[],["subscribed"],["emitted",["1,2,3"]],["unsubscribed",0],["emitted",[7]]] +输出:[[],["subscribed"],["subscribed"],["unsubscribed",0],["emitted",[7]]] 解释: const emitter = new EventEmitter(); const sub1 = emitter.subscribe("firstEvent", x => x + 1); diff --git a/solution/2600-2699/2694.Event Emitter/README_EN.md b/solution/2600-2699/2694.Event Emitter/README_EN.md index 6759594507da2..df4221390cb54 100644 --- a/solution/2600-2699/2694.Event Emitter/README_EN.md +++ b/solution/2600-2699/2694.Event Emitter/README_EN.md @@ -79,7 +79,7 @@ emitter.emit("firstEvent", [4, 5, 6]); // [], there are no subscriptio Input: actions = ["EventEmitter", "subscribe", "subscribe", "unsubscribe", "emit"], values = [[], ["firstEvent", "x => x + 1"], ["firstEvent", "x => x + 2"], [0], ["firstEvent", [5]]] -Output: [[],["subscribed"],["emitted",["1,2,3"]],["unsubscribed",0],["emitted",[7]]] +Output: [[],["subscribed"],["subscribed"],["unsubscribed",0],["emitted",[7]]] Explanation: const emitter = new EventEmitter(); const sub1 = emitter.subscribe("firstEvent", x => x + 1); diff --git a/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README.md b/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README.md index a5fdf8b774601..167074aa40056 100644 --- a/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README.md +++ b/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README.md @@ -22,14 +22,12 @@ tags: -

    你在一个水果超市里,货架上摆满了玲琅满目的奇珍异果。

    - -

    给你一个下标从 1 开始的数组 prices ,其中 prices[i] 表示你购买第 i 个水果需要花费的金币数目。

    +

    给你一个 下标从 1 开始的 整数数组 prices ,其中 prices[i] 表示你购买第 i 个水果需要花费的金币数目。

    水果超市有如下促销活动:

    注意 ,即使你 可以 免费获得水果 j ,你仍然可以花费 prices[j] 个金币去购买它以获得它的奖励。

    diff --git a/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README_EN.md b/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README_EN.md index fc6d3b6e7be53..c269d8314e373 100644 --- a/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README_EN.md +++ b/solution/2900-2999/2944.Minimum Number of Coins for Fruits/README_EN.md @@ -22,12 +22,12 @@ tags: -

    You are given an integer array prices where prices[i] denotes the number of coins needed to purchase the ith fruit.

    +

    You are given an 1-indexed integer array prices where prices[i] denotes the number of coins needed to purchase the ith fruit.

    The fruit market has the following reward for each fruit:

    Note that even if you can take fruit j for free, you can still purchase it for prices[j] coins to receive its reward.

    diff --git a/solution/3300-3399/3314.Construct the Minimum Bitwise Array I/README.md b/solution/3300-3399/3314.Construct the Minimum Bitwise Array I/README.md index 017f4a2fae88d..e4044291622c7 100644 --- a/solution/3300-3399/3314.Construct the Minimum Bitwise Array I/README.md +++ b/solution/3300-3399/3314.Construct the Minimum Bitwise Array I/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 简单 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3314.Construct%20the%20Minimum%20Bitwise%20Array%20I/README.md +rating: 1378 +source: 第 141 场双周赛 Q1 tags: - 位运算 - 数组 diff --git a/solution/3300-3399/3314.Construct the Minimum Bitwise Array I/README_EN.md b/solution/3300-3399/3314.Construct the Minimum Bitwise Array I/README_EN.md index e2c4536d7f2fd..a3d6dc240aea3 100644 --- a/solution/3300-3399/3314.Construct the Minimum Bitwise Array I/README_EN.md +++ b/solution/3300-3399/3314.Construct the Minimum Bitwise Array I/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Easy edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3314.Construct%20the%20Minimum%20Bitwise%20Array%20I/README_EN.md +rating: 1378 +source: Biweekly Contest 141 Q1 tags: - Bit Manipulation - Array diff --git a/solution/3300-3399/3315.Construct the Minimum Bitwise Array II/README.md b/solution/3300-3399/3315.Construct the Minimum Bitwise Array II/README.md index 02dae50a9bd9c..0888633a82511 100644 --- a/solution/3300-3399/3315.Construct the Minimum Bitwise Array II/README.md +++ b/solution/3300-3399/3315.Construct the Minimum Bitwise Array II/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3315.Construct%20the%20Minimum%20Bitwise%20Array%20II/README.md +rating: 1714 +source: 第 141 场双周赛 Q2 tags: - 位运算 - 数组 diff --git a/solution/3300-3399/3315.Construct the Minimum Bitwise Array II/README_EN.md b/solution/3300-3399/3315.Construct the Minimum Bitwise Array II/README_EN.md index d24fe77a17264..625cdd14cd43b 100644 --- a/solution/3300-3399/3315.Construct the Minimum Bitwise Array II/README_EN.md +++ b/solution/3300-3399/3315.Construct the Minimum Bitwise Array II/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3315.Construct%20the%20Minimum%20Bitwise%20Array%20II/README_EN.md +rating: 1714 +source: Biweekly Contest 141 Q2 tags: - Bit Manipulation - Array diff --git a/solution/3300-3399/3316.Find Maximum Removals From Source String/README.md b/solution/3300-3399/3316.Find Maximum Removals From Source String/README.md index 1e401ea7e5c20..a56876a5c3173 100644 --- a/solution/3300-3399/3316.Find Maximum Removals From Source String/README.md +++ b/solution/3300-3399/3316.Find Maximum Removals From Source String/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3316.Find%20Maximum%20Removals%20From%20Source%20String/README.md +rating: 2062 +source: 第 141 场双周赛 Q3 tags: - 数组 - 哈希表 diff --git a/solution/3300-3399/3316.Find Maximum Removals From Source String/README_EN.md b/solution/3300-3399/3316.Find Maximum Removals From Source String/README_EN.md index 3c83f2c940da1..399961daa0093 100644 --- a/solution/3300-3399/3316.Find Maximum Removals From Source String/README_EN.md +++ b/solution/3300-3399/3316.Find Maximum Removals From Source String/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3316.Find%20Maximum%20Removals%20From%20Source%20String/README_EN.md +rating: 2062 +source: Biweekly Contest 141 Q3 tags: - Array - Hash Table diff --git a/solution/3300-3399/3317.Find the Number of Possible Ways for an Event/README.md b/solution/3300-3399/3317.Find the Number of Possible Ways for an Event/README.md index ad49c17f04cfc..2912d859b6619 100644 --- a/solution/3300-3399/3317.Find the Number of Possible Ways for an Event/README.md +++ b/solution/3300-3399/3317.Find the Number of Possible Ways for an Event/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 困难 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3317.Find%20the%20Number%20of%20Possible%20Ways%20for%20an%20Event/README.md +rating: 2413 +source: 第 141 场双周赛 Q4 tags: - 数学 - 动态规划 diff --git a/solution/3300-3399/3317.Find the Number of Possible Ways for an Event/README_EN.md b/solution/3300-3399/3317.Find the Number of Possible Ways for an Event/README_EN.md index d23cee3b2cfbf..c02f932b77250 100644 --- a/solution/3300-3399/3317.Find the Number of Possible Ways for an Event/README_EN.md +++ b/solution/3300-3399/3317.Find the Number of Possible Ways for an Event/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Hard edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3317.Find%20the%20Number%20of%20Possible%20Ways%20for%20an%20Event/README_EN.md +rating: 2413 +source: Biweekly Contest 141 Q4 tags: - Math - Dynamic Programming diff --git a/solution/3300-3399/3318.Find X-Sum of All K-Long Subarrays I/README.md b/solution/3300-3399/3318.Find X-Sum of All K-Long Subarrays I/README.md index 7783225448051..5cf065fe6afef 100644 --- a/solution/3300-3399/3318.Find X-Sum of All K-Long Subarrays I/README.md +++ b/solution/3300-3399/3318.Find X-Sum of All K-Long Subarrays I/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 简单 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3318.Find%20X-Sum%20of%20All%20K-Long%20Subarrays%20I/README.md +rating: 1457 +source: 第 419 场周赛 Q1 tags: - 数组 - 哈希表 diff --git a/solution/3300-3399/3318.Find X-Sum of All K-Long Subarrays I/README_EN.md b/solution/3300-3399/3318.Find X-Sum of All K-Long Subarrays I/README_EN.md index 94c4a419b6c92..6672fc4706bdc 100644 --- a/solution/3300-3399/3318.Find X-Sum of All K-Long Subarrays I/README_EN.md +++ b/solution/3300-3399/3318.Find X-Sum of All K-Long Subarrays I/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Easy edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3318.Find%20X-Sum%20of%20All%20K-Long%20Subarrays%20I/README_EN.md +rating: 1457 +source: Weekly Contest 419 Q1 tags: - Array - Hash Table diff --git a/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README.md b/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README.md index 60f93f9b3f0cf..7b19c8e24268c 100644 --- a/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README.md +++ b/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3319.K-th%20Largest%20Perfect%20Subtree%20Size%20in%20Binary%20Tree/README.md +rating: 1603 +source: 第 419 场周赛 Q2 tags: - 树 - 深度优先搜索 diff --git a/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README_EN.md b/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README_EN.md index 1c4353ef2d369..056e565492d2f 100644 --- a/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README_EN.md +++ b/solution/3300-3399/3319.K-th Largest Perfect Subtree Size in Binary Tree/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3319.K-th%20Largest%20Perfect%20Subtree%20Size%20in%20Binary%20Tree/README_EN.md +rating: 1603 +source: Weekly Contest 419 Q2 tags: - Tree - Depth-First Search diff --git a/solution/3300-3399/3320.Count The Number of Winning Sequences/README.md b/solution/3300-3399/3320.Count The Number of Winning Sequences/README.md index 5fb78f3564b47..56bfef572d355 100644 --- a/solution/3300-3399/3320.Count The Number of Winning Sequences/README.md +++ b/solution/3300-3399/3320.Count The Number of Winning Sequences/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 困难 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3320.Count%20The%20Number%20of%20Winning%20Sequences/README.md +rating: 2153 +source: 第 419 场周赛 Q3 tags: - 字符串 - 动态规划 diff --git a/solution/3300-3399/3320.Count The Number of Winning Sequences/README_EN.md b/solution/3300-3399/3320.Count The Number of Winning Sequences/README_EN.md index 1972b87a463ca..444532f2a68b6 100644 --- a/solution/3300-3399/3320.Count The Number of Winning Sequences/README_EN.md +++ b/solution/3300-3399/3320.Count The Number of Winning Sequences/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Hard edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3320.Count%20The%20Number%20of%20Winning%20Sequences/README_EN.md +rating: 2153 +source: Weekly Contest 419 Q3 tags: - String - Dynamic Programming diff --git a/solution/3300-3399/3321.Find X-Sum of All K-Long Subarrays II/README.md b/solution/3300-3399/3321.Find X-Sum of All K-Long Subarrays II/README.md index b255f40c499c4..bdc1c78e86c45 100644 --- a/solution/3300-3399/3321.Find X-Sum of All K-Long Subarrays II/README.md +++ b/solution/3300-3399/3321.Find X-Sum of All K-Long Subarrays II/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 困难 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3321.Find%20X-Sum%20of%20All%20K-Long%20Subarrays%20II/README.md +rating: 2598 +source: 第 419 场周赛 Q4 tags: - 数组 - 哈希表 diff --git a/solution/3300-3399/3321.Find X-Sum of All K-Long Subarrays II/README_EN.md b/solution/3300-3399/3321.Find X-Sum of All K-Long Subarrays II/README_EN.md index 247e1b59f02f8..7d676552bafe8 100644 --- a/solution/3300-3399/3321.Find X-Sum of All K-Long Subarrays II/README_EN.md +++ b/solution/3300-3399/3321.Find X-Sum of All K-Long Subarrays II/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Hard edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3321.Find%20X-Sum%20of%20All%20K-Long%20Subarrays%20II/README_EN.md +rating: 2598 +source: Weekly Contest 419 Q4 tags: - Array - Hash Table diff --git a/solution/3300-3399/3324.Find the Sequence of Strings Appeared on the Screen/README.md b/solution/3300-3399/3324.Find the Sequence of Strings Appeared on the Screen/README.md index f2feb30499d9b..0a96eaa22387d 100644 --- a/solution/3300-3399/3324.Find the Sequence of Strings Appeared on the Screen/README.md +++ b/solution/3300-3399/3324.Find the Sequence of Strings Appeared on the Screen/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3324.Find%20the%20Sequence%20of%20Strings%20Appeared%20on%20the%20Screen/README.md +rating: 1293 +source: 第 420 场周赛 Q1 tags: - 字符串 - 模拟 diff --git a/solution/3300-3399/3324.Find the Sequence of Strings Appeared on the Screen/README_EN.md b/solution/3300-3399/3324.Find the Sequence of Strings Appeared on the Screen/README_EN.md index 601234de324b2..804dfda7683e8 100644 --- a/solution/3300-3399/3324.Find the Sequence of Strings Appeared on the Screen/README_EN.md +++ b/solution/3300-3399/3324.Find the Sequence of Strings Appeared on the Screen/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3324.Find%20the%20Sequence%20of%20Strings%20Appeared%20on%20the%20Screen/README_EN.md +rating: 1293 +source: Weekly Contest 420 Q1 tags: - String - Simulation diff --git a/solution/3300-3399/3325.Count Substrings With K-Frequency Characters I/README.md b/solution/3300-3399/3325.Count Substrings With K-Frequency Characters I/README.md index 93761f31e34fb..290aeabd4e25b 100644 --- a/solution/3300-3399/3325.Count Substrings With K-Frequency Characters I/README.md +++ b/solution/3300-3399/3325.Count Substrings With K-Frequency Characters I/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3325.Count%20Substrings%20With%20K-Frequency%20Characters%20I/README.md +rating: 1454 +source: 第 420 场周赛 Q2 tags: - 哈希表 - 字符串 diff --git a/solution/3300-3399/3325.Count Substrings With K-Frequency Characters I/README_EN.md b/solution/3300-3399/3325.Count Substrings With K-Frequency Characters I/README_EN.md index f5d189505892e..bad8c13731d51 100644 --- a/solution/3300-3399/3325.Count Substrings With K-Frequency Characters I/README_EN.md +++ b/solution/3300-3399/3325.Count Substrings With K-Frequency Characters I/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3325.Count%20Substrings%20With%20K-Frequency%20Characters%20I/README_EN.md +rating: 1454 +source: Weekly Contest 420 Q2 tags: - Hash Table - String diff --git a/solution/3300-3399/3326.Minimum Division Operations to Make Array Non Decreasing/README.md b/solution/3300-3399/3326.Minimum Division Operations to Make Array Non Decreasing/README.md index 7a8e8b441e537..32226346c2c09 100644 --- a/solution/3300-3399/3326.Minimum Division Operations to Make Array Non Decreasing/README.md +++ b/solution/3300-3399/3326.Minimum Division Operations to Make Array Non Decreasing/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3326.Minimum%20Division%20Operations%20to%20Make%20Array%20Non%20Decreasing/README.md +rating: 1864 +source: 第 420 场周赛 Q3 tags: - 贪心 - 数组 diff --git a/solution/3300-3399/3326.Minimum Division Operations to Make Array Non Decreasing/README_EN.md b/solution/3300-3399/3326.Minimum Division Operations to Make Array Non Decreasing/README_EN.md index 5e6d7609f02fd..22e2d562470de 100644 --- a/solution/3300-3399/3326.Minimum Division Operations to Make Array Non Decreasing/README_EN.md +++ b/solution/3300-3399/3326.Minimum Division Operations to Make Array Non Decreasing/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3326.Minimum%20Division%20Operations%20to%20Make%20Array%20Non%20Decreasing/README_EN.md +rating: 1864 +source: Weekly Contest 420 Q3 tags: - Greedy - Array diff --git a/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README.md b/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README.md index 043f1dfbd358c..9ed9cae91e589 100644 --- a/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README.md +++ b/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 困难 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3327.Check%20if%20DFS%20Strings%20Are%20Palindromes/README.md +rating: 2454 +source: 第 420 场周赛 Q4 tags: - 树 - 深度优先搜索 diff --git a/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README_EN.md b/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README_EN.md index 09680e6c4c74c..1333ab1327add 100644 --- a/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README_EN.md +++ b/solution/3300-3399/3327.Check if DFS Strings Are Palindromes/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Hard edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3327.Check%20if%20DFS%20Strings%20Are%20Palindromes/README_EN.md +rating: 2454 +source: Weekly Contest 420 Q4 tags: - Tree - Depth-First Search diff --git a/solution/3300-3399/3330.Find the Original Typed String I/README.md b/solution/3300-3399/3330.Find the Original Typed String I/README.md index b68a474e12cdd..5c9ac9f00ee7e 100644 --- a/solution/3300-3399/3330.Find the Original Typed String I/README.md +++ b/solution/3300-3399/3330.Find the Original Typed String I/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 简单 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3330.Find%20the%20Original%20Typed%20String%20I/README.md +rating: 1338 +source: 第 142 场双周赛 Q1 tags: - 字符串 --- diff --git a/solution/3300-3399/3330.Find the Original Typed String I/README_EN.md b/solution/3300-3399/3330.Find the Original Typed String I/README_EN.md index 702b8b2a16d58..e6708d554969c 100644 --- a/solution/3300-3399/3330.Find the Original Typed String I/README_EN.md +++ b/solution/3300-3399/3330.Find the Original Typed String I/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Easy edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3330.Find%20the%20Original%20Typed%20String%20I/README_EN.md +rating: 1338 +source: Biweekly Contest 142 Q1 tags: - String --- diff --git a/solution/3300-3399/3331.Find Subtree Sizes After Changes/README.md b/solution/3300-3399/3331.Find Subtree Sizes After Changes/README.md index 64e9d7779a3cc..45655238350a7 100644 --- a/solution/3300-3399/3331.Find Subtree Sizes After Changes/README.md +++ b/solution/3300-3399/3331.Find Subtree Sizes After Changes/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3331.Find%20Subtree%20Sizes%20After%20Changes/README.md +rating: 2045 +source: 第 142 场双周赛 Q2 tags: - 树 - 深度优先搜索 diff --git a/solution/3300-3399/3331.Find Subtree Sizes After Changes/README_EN.md b/solution/3300-3399/3331.Find Subtree Sizes After Changes/README_EN.md index a974bae5c974b..c3a3810b5462e 100644 --- a/solution/3300-3399/3331.Find Subtree Sizes After Changes/README_EN.md +++ b/solution/3300-3399/3331.Find Subtree Sizes After Changes/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3331.Find%20Subtree%20Sizes%20After%20Changes/README_EN.md +rating: 2045 +source: Biweekly Contest 142 Q2 tags: - Tree - Depth-First Search diff --git a/solution/3300-3399/3332.Maximum Points Tourist Can Earn/README.md b/solution/3300-3399/3332.Maximum Points Tourist Can Earn/README.md index 503251b7614b0..5d3078c53ba3e 100644 --- a/solution/3300-3399/3332.Maximum Points Tourist Can Earn/README.md +++ b/solution/3300-3399/3332.Maximum Points Tourist Can Earn/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3332.Maximum%20Points%20Tourist%20Can%20Earn/README.md +rating: 1827 +source: 第 142 场双周赛 Q3 tags: - 数组 - 动态规划 diff --git a/solution/3300-3399/3332.Maximum Points Tourist Can Earn/README_EN.md b/solution/3300-3399/3332.Maximum Points Tourist Can Earn/README_EN.md index 8f186f0129bc7..831f3b058c974 100644 --- a/solution/3300-3399/3332.Maximum Points Tourist Can Earn/README_EN.md +++ b/solution/3300-3399/3332.Maximum Points Tourist Can Earn/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3332.Maximum%20Points%20Tourist%20Can%20Earn/README_EN.md +rating: 1827 +source: Biweekly Contest 142 Q3 tags: - Array - Dynamic Programming diff --git a/solution/3300-3399/3333.Find the Original Typed String II/README.md b/solution/3300-3399/3333.Find the Original Typed String II/README.md index 027c1f56019f7..2f146eea6be79 100644 --- a/solution/3300-3399/3333.Find the Original Typed String II/README.md +++ b/solution/3300-3399/3333.Find the Original Typed String II/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 困难 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3333.Find%20the%20Original%20Typed%20String%20II/README.md +rating: 2628 +source: 第 142 场双周赛 Q4 tags: - 字符串 - 动态规划 diff --git a/solution/3300-3399/3333.Find the Original Typed String II/README_EN.md b/solution/3300-3399/3333.Find the Original Typed String II/README_EN.md index 7a42fcd213ad8..88fd2da02fb2c 100644 --- a/solution/3300-3399/3333.Find the Original Typed String II/README_EN.md +++ b/solution/3300-3399/3333.Find the Original Typed String II/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Hard edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3333.Find%20the%20Original%20Typed%20String%20II/README_EN.md +rating: 2628 +source: Biweekly Contest 142 Q4 tags: - String - Dynamic Programming diff --git a/solution/3300-3399/3334.Find the Maximum Factor Score of Array/README.md b/solution/3300-3399/3334.Find the Maximum Factor Score of Array/README.md index ee3be01c48bd6..99cbd743f55f2 100644 --- a/solution/3300-3399/3334.Find the Maximum Factor Score of Array/README.md +++ b/solution/3300-3399/3334.Find the Maximum Factor Score of Array/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3334.Find%20the%20Maximum%20Factor%20Score%20of%20Array/README.md +rating: 1518 +source: 第 421 场周赛 Q1 tags: - 数组 - 数学 diff --git a/solution/3300-3399/3334.Find the Maximum Factor Score of Array/README_EN.md b/solution/3300-3399/3334.Find the Maximum Factor Score of Array/README_EN.md index f2b6bb85978ee..4226140102de3 100644 --- a/solution/3300-3399/3334.Find the Maximum Factor Score of Array/README_EN.md +++ b/solution/3300-3399/3334.Find the Maximum Factor Score of Array/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3334.Find%20the%20Maximum%20Factor%20Score%20of%20Array/README_EN.md +rating: 1518 +source: Weekly Contest 421 Q1 tags: - Array - Math diff --git a/solution/3300-3399/3335.Total Characters in String After Transformations I/README.md b/solution/3300-3399/3335.Total Characters in String After Transformations I/README.md index 803e83832527b..950893ee82e13 100644 --- a/solution/3300-3399/3335.Total Characters in String After Transformations I/README.md +++ b/solution/3300-3399/3335.Total Characters in String After Transformations I/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3335.Total%20Characters%20in%20String%20After%20Transformations%20I/README.md +rating: 1806 +source: 第 421 场周赛 Q2 tags: - 哈希表 - 数学 diff --git a/solution/3300-3399/3335.Total Characters in String After Transformations I/README_EN.md b/solution/3300-3399/3335.Total Characters in String After Transformations I/README_EN.md index b5f2ed836ddcb..dfc8513a27e26 100644 --- a/solution/3300-3399/3335.Total Characters in String After Transformations I/README_EN.md +++ b/solution/3300-3399/3335.Total Characters in String After Transformations I/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3335.Total%20Characters%20in%20String%20After%20Transformations%20I/README_EN.md +rating: 1806 +source: Weekly Contest 421 Q2 tags: - Hash Table - Math diff --git a/solution/3300-3399/3336.Find the Number of Subsequences With Equal GCD/README.md b/solution/3300-3399/3336.Find the Number of Subsequences With Equal GCD/README.md index c5f9b8468c147..f314692b7210c 100644 --- a/solution/3300-3399/3336.Find the Number of Subsequences With Equal GCD/README.md +++ b/solution/3300-3399/3336.Find the Number of Subsequences With Equal GCD/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 困难 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3336.Find%20the%20Number%20of%20Subsequences%20With%20Equal%20GCD/README.md +rating: 2402 +source: 第 421 场周赛 Q3 tags: - 数组 - 数学 diff --git a/solution/3300-3399/3336.Find the Number of Subsequences With Equal GCD/README_EN.md b/solution/3300-3399/3336.Find the Number of Subsequences With Equal GCD/README_EN.md index 54937439fe939..5b900e2b4fe87 100644 --- a/solution/3300-3399/3336.Find the Number of Subsequences With Equal GCD/README_EN.md +++ b/solution/3300-3399/3336.Find the Number of Subsequences With Equal GCD/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Hard edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3336.Find%20the%20Number%20of%20Subsequences%20With%20Equal%20GCD/README_EN.md +rating: 2402 +source: Weekly Contest 421 Q3 tags: - Array - Math diff --git a/solution/3300-3399/3337.Total Characters in String After Transformations II/README.md b/solution/3300-3399/3337.Total Characters in String After Transformations II/README.md index 26f128d93e293..0cfe618ae042a 100644 --- a/solution/3300-3399/3337.Total Characters in String After Transformations II/README.md +++ b/solution/3300-3399/3337.Total Characters in String After Transformations II/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 困难 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3337.Total%20Characters%20in%20String%20After%20Transformations%20II/README.md +rating: 2411 +source: 第 421 场周赛 Q4 tags: - 哈希表 - 数学 diff --git a/solution/3300-3399/3337.Total Characters in String After Transformations II/README_EN.md b/solution/3300-3399/3337.Total Characters in String After Transformations II/README_EN.md index 1e3ba5e6aea8e..8088af730786c 100644 --- a/solution/3300-3399/3337.Total Characters in String After Transformations II/README_EN.md +++ b/solution/3300-3399/3337.Total Characters in String After Transformations II/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Hard edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3337.Total%20Characters%20in%20String%20After%20Transformations%20II/README_EN.md +rating: 2411 +source: Weekly Contest 421 Q4 tags: - Hash Table - Math diff --git a/solution/3300-3399/3340.Check Balanced String/README.md b/solution/3300-3399/3340.Check Balanced String/README.md index f107c94d4713e..7267b417f0f61 100644 --- a/solution/3300-3399/3340.Check Balanced String/README.md +++ b/solution/3300-3399/3340.Check Balanced String/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 简单 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3340.Check%20Balanced%20String/README.md +rating: 1190 +source: 第 422 场周赛 Q1 tags: - 字符串 --- diff --git a/solution/3300-3399/3340.Check Balanced String/README_EN.md b/solution/3300-3399/3340.Check Balanced String/README_EN.md index f174facb93812..a3d84bbb4a42b 100644 --- a/solution/3300-3399/3340.Check Balanced String/README_EN.md +++ b/solution/3300-3399/3340.Check Balanced String/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Easy edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3340.Check%20Balanced%20String/README_EN.md +rating: 1190 +source: Weekly Contest 422 Q1 tags: - String --- diff --git a/solution/3300-3399/3341.Find Minimum Time to Reach Last Room I/README.md b/solution/3300-3399/3341.Find Minimum Time to Reach Last Room I/README.md index 364565a827492..ab8618f39a512 100644 --- a/solution/3300-3399/3341.Find Minimum Time to Reach Last Room I/README.md +++ b/solution/3300-3399/3341.Find Minimum Time to Reach Last Room I/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3341.Find%20Minimum%20Time%20to%20Reach%20Last%20Room%20I/README.md +rating: 1721 +source: 第 422 场周赛 Q2 tags: - 图 - 数组 diff --git a/solution/3300-3399/3341.Find Minimum Time to Reach Last Room I/README_EN.md b/solution/3300-3399/3341.Find Minimum Time to Reach Last Room I/README_EN.md index f44c667220e08..eb0c654f6e62d 100644 --- a/solution/3300-3399/3341.Find Minimum Time to Reach Last Room I/README_EN.md +++ b/solution/3300-3399/3341.Find Minimum Time to Reach Last Room I/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3341.Find%20Minimum%20Time%20to%20Reach%20Last%20Room%20I/README_EN.md +rating: 1721 +source: Weekly Contest 422 Q2 tags: - Graph - Array diff --git a/solution/3300-3399/3342.Find Minimum Time to Reach Last Room II/README.md b/solution/3300-3399/3342.Find Minimum Time to Reach Last Room II/README.md index c34481b8bc319..ee5bc219b1c5f 100644 --- a/solution/3300-3399/3342.Find Minimum Time to Reach Last Room II/README.md +++ b/solution/3300-3399/3342.Find Minimum Time to Reach Last Room II/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 中等 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3342.Find%20Minimum%20Time%20to%20Reach%20Last%20Room%20II/README.md +rating: 1861 +source: 第 422 场周赛 Q3 tags: - 图 - 数组 diff --git a/solution/3300-3399/3342.Find Minimum Time to Reach Last Room II/README_EN.md b/solution/3300-3399/3342.Find Minimum Time to Reach Last Room II/README_EN.md index 8fc2a3b39e2fa..e9dd0768112ee 100644 --- a/solution/3300-3399/3342.Find Minimum Time to Reach Last Room II/README_EN.md +++ b/solution/3300-3399/3342.Find Minimum Time to Reach Last Room II/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Medium edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3342.Find%20Minimum%20Time%20to%20Reach%20Last%20Room%20II/README_EN.md +rating: 1861 +source: Weekly Contest 422 Q3 tags: - Graph - Array diff --git a/solution/3300-3399/3343.Count Number of Balanced Permutations/README.md b/solution/3300-3399/3343.Count Number of Balanced Permutations/README.md index cb84d730105ab..dac4ebcc67205 100644 --- a/solution/3300-3399/3343.Count Number of Balanced Permutations/README.md +++ b/solution/3300-3399/3343.Count Number of Balanced Permutations/README.md @@ -2,6 +2,8 @@ comments: true difficulty: 困难 edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3343.Count%20Number%20of%20Balanced%20Permutations/README.md +rating: 2614 +source: 第 422 场周赛 Q4 tags: - 数学 - 字符串 diff --git a/solution/3300-3399/3343.Count Number of Balanced Permutations/README_EN.md b/solution/3300-3399/3343.Count Number of Balanced Permutations/README_EN.md index 1ca3211a9522e..5c1e5db223468 100644 --- a/solution/3300-3399/3343.Count Number of Balanced Permutations/README_EN.md +++ b/solution/3300-3399/3343.Count Number of Balanced Permutations/README_EN.md @@ -2,6 +2,8 @@ comments: true difficulty: Hard edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3343.Count%20Number%20of%20Balanced%20Permutations/README_EN.md +rating: 2614 +source: Weekly Contest 422 Q4 tags: - Math - String diff --git a/solution/3300-3399/3353.Minimum Total Operations/README.md b/solution/3300-3399/3353.Minimum Total Operations/README.md new file mode 100644 index 0000000000000..9e33b636efdcc --- /dev/null +++ b/solution/3300-3399/3353.Minimum Total Operations/README.md @@ -0,0 +1,149 @@ +--- +comments: true +difficulty: 简单 +edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3353.Minimum%20Total%20Operations/README.md +--- + + + +# [3353. Minimum Total Operations 🔒](https://leetcode.cn/problems/minimum-total-operations) + +[English Version](/solution/3300-3399/3353.Minimum%20Total%20Operations/README_EN.md) + +## 题目描述 + + + +

    Given an array of integers nums, you can perform any number of operations on this array.

    + +

    In each operation, you can:

    + + + +

    A prefix of an array is a subarray that starts from the beginning of the array and extends to any point within it.

    + +

    Return the minimum number of operations required to make all elements in arr equal.

    + +

     

    +

    Example 1:

    + +
    +

    Input: nums = [1,4,2]

    + +

    Output: 2

    + +

    Explanation:

    + + +
    + +

    Example 2:

    + +
    +

    Input: nums = [10,10,10]

    + +

    Output: 0

    + +

    Explanation:

    + + +
    + +

     

    +

    Constraints:

    + + + + + +## 解法 + + + +### 方法一:一次遍历 + +我们可以遍历数组,对于每个元素,如果它与前一个元素不相等,那么就需要进行一次操作,最后返回操作的次数即可。 + +时间复杂度 $O(n)$,其中 $n$ 为数组的长度。空间复杂度 $O(1)$。 + + + +#### Python3 + +```python +class Solution: + def minOperations(self, nums: List[int]) -> int: + return sum(x != y for x, y in pairwise(nums)) +``` + +#### Java + +```java +class Solution { + public int minOperations(int[] nums) { + int ans = 0; + for (int i = 1; i < nums.length; ++i) { + ans += nums[i] != nums[i - 1] ? 1 : 0; + } + return ans; + } +} +``` + +#### C++ + +```cpp +class Solution { +public: + int minOperations(vector& nums) { + int ans = 0; + for (int i = 1; i < nums.size(); ++i) { + ans += nums[i] != nums[i - 1]; + } + return ans; + } +}; +``` + +#### Go + +```go +func minOperations(nums []int) (ans int) { + for i, x := range nums[1:] { + if x != nums[i] { + ans++ + } + } + return +} +``` + +#### TypeScript + +```ts +function minOperations(nums: number[]): number { + let ans = 0; + for (let i = 1; i < nums.length; ++i) { + ans += nums[i] !== nums[i - 1] ? 1 : 0; + } + return ans; +} +``` + + + + + + diff --git a/solution/3300-3399/3353.Minimum Total Operations/README_EN.md b/solution/3300-3399/3353.Minimum Total Operations/README_EN.md new file mode 100644 index 0000000000000..f872ebdf535b0 --- /dev/null +++ b/solution/3300-3399/3353.Minimum Total Operations/README_EN.md @@ -0,0 +1,149 @@ +--- +comments: true +difficulty: Easy +edit_url: https://github.com/doocs/leetcode/edit/main/solution/3300-3399/3353.Minimum%20Total%20Operations/README_EN.md +--- + + + +# [3353. Minimum Total Operations 🔒](https://leetcode.com/problems/minimum-total-operations) + +[中文文档](/solution/3300-3399/3353.Minimum%20Total%20Operations/README.md) + +## Description + + + +

    Given an array of integers nums, you can perform any number of operations on this array.

    + +

    In each operation, you can:

    + + + +

    A prefix of an array is a subarray that starts from the beginning of the array and extends to any point within it.

    + +

    Return the minimum number of operations required to make all elements in arr equal.

    + +

     

    +

    Example 1:

    + +
    +

    Input: nums = [1,4,2]

    + +

    Output: 2

    + +

    Explanation:

    + +
      +
    • Operation 1: Choose the prefix [1, 4] of length 2 and add -2 to each element of the prefix. The array becomes [-1, 2, 2].
    • +
    • Operation 2: Choose the prefix [-1] of length 1 and add 3 to it. The array becomes [2, 2, 2].
    • +
    • Thus, the minimum number of required operations is 2.
    • +
    +
    + +

    Example 2:

    + +
    +

    Input: nums = [10,10,10]

    + +

    Output: 0

    + +

    Explanation:

    + +
      +
    • All elements are already equal, so no operations are needed.
    • +
    +
    + +

     

    +

    Constraints:

    + + + + + +## Solutions + + + +### Solution 1: Single Pass + +We can traverse the array, and for each element, if it is not equal to the previous element, we need to perform an operation. Finally, we return the number of operations. + +The time complexity is $O(n)$, where $n$ is the length of the array. The space complexity is $O(1)$. + + + +#### Python3 + +```python +class Solution: + def minOperations(self, nums: List[int]) -> int: + return sum(x != y for x, y in pairwise(nums)) +``` + +#### Java + +```java +class Solution { + public int minOperations(int[] nums) { + int ans = 0; + for (int i = 1; i < nums.length; ++i) { + ans += nums[i] != nums[i - 1] ? 1 : 0; + } + return ans; + } +} +``` + +#### C++ + +```cpp +class Solution { +public: + int minOperations(vector& nums) { + int ans = 0; + for (int i = 1; i < nums.size(); ++i) { + ans += nums[i] != nums[i - 1]; + } + return ans; + } +}; +``` + +#### Go + +```go +func minOperations(nums []int) (ans int) { + for i, x := range nums[1:] { + if x != nums[i] { + ans++ + } + } + return +} +``` + +#### TypeScript + +```ts +function minOperations(nums: number[]): number { + let ans = 0; + for (let i = 1; i < nums.length; ++i) { + ans += nums[i] !== nums[i - 1] ? 1 : 0; + } + return ans; +} +``` + + + + + + diff --git a/solution/3300-3399/3353.Minimum Total Operations/Solution.cpp b/solution/3300-3399/3353.Minimum Total Operations/Solution.cpp new file mode 100644 index 0000000000000..6badaaade2203 --- /dev/null +++ b/solution/3300-3399/3353.Minimum Total Operations/Solution.cpp @@ -0,0 +1,10 @@ +class Solution { +public: + int minOperations(vector& nums) { + int ans = 0; + for (int i = 1; i < nums.size(); ++i) { + ans += nums[i] != nums[i - 1]; + } + return ans; + } +}; diff --git a/solution/3300-3399/3353.Minimum Total Operations/Solution.go b/solution/3300-3399/3353.Minimum Total Operations/Solution.go new file mode 100644 index 0000000000000..8bf638b34fd53 --- /dev/null +++ b/solution/3300-3399/3353.Minimum Total Operations/Solution.go @@ -0,0 +1,8 @@ +func minOperations(nums []int) (ans int) { + for i, x := range nums[1:] { + if x != nums[i] { + ans++ + } + } + return +} diff --git a/solution/3300-3399/3353.Minimum Total Operations/Solution.java b/solution/3300-3399/3353.Minimum Total Operations/Solution.java new file mode 100644 index 0000000000000..209724a94fd5a --- /dev/null +++ b/solution/3300-3399/3353.Minimum Total Operations/Solution.java @@ -0,0 +1,9 @@ +class Solution { + public int minOperations(int[] nums) { + int ans = 0; + for (int i = 1; i < nums.length; ++i) { + ans += nums[i] != nums[i - 1] ? 1 : 0; + } + return ans; + } +} diff --git a/solution/3300-3399/3353.Minimum Total Operations/Solution.py b/solution/3300-3399/3353.Minimum Total Operations/Solution.py new file mode 100644 index 0000000000000..63d00803bf1bd --- /dev/null +++ b/solution/3300-3399/3353.Minimum Total Operations/Solution.py @@ -0,0 +1,3 @@ +class Solution: + def minOperations(self, nums: List[int]) -> int: + return sum(x != y for x, y in pairwise(nums)) diff --git a/solution/3300-3399/3353.Minimum Total Operations/Solution.ts b/solution/3300-3399/3353.Minimum Total Operations/Solution.ts new file mode 100644 index 0000000000000..86813b2dc99fc --- /dev/null +++ b/solution/3300-3399/3353.Minimum Total Operations/Solution.ts @@ -0,0 +1,7 @@ +function minOperations(nums: number[]): number { + let ans = 0; + for (let i = 1; i < nums.length; ++i) { + ans += nums[i] !== nums[i - 1] ? 1 : 0; + } + return ans; +} diff --git a/solution/README.md b/solution/README.md index 0b8b2024a1177..96ce1aaddbea2 100644 --- a/solution/README.md +++ b/solution/README.md @@ -394,7 +394,7 @@ | 0381 | [O(1) 时间插入、删除和获取随机元素 - 允许重复](/solution/0300-0399/0381.Insert%20Delete%20GetRandom%20O%281%29%20-%20Duplicates%20allowed/README.md) | `设计`,`数组`,`哈希表`,`数学`,`随机化` | 困难 | | | 0382 | [链表随机节点](/solution/0300-0399/0382.Linked%20List%20Random%20Node/README.md) | `水塘抽样`,`链表`,`数学`,`随机化` | 中等 | | | 0383 | [赎金信](/solution/0300-0399/0383.Ransom%20Note/README.md) | `哈希表`,`字符串`,`计数` | 简单 | | -| 0384 | [打乱数组](/solution/0300-0399/0384.Shuffle%20an%20Array/README.md) | `数组`,`数学`,`随机化` | 中等 | | +| 0384 | [打乱数组](/solution/0300-0399/0384.Shuffle%20an%20Array/README.md) | `设计`,`数组`,`数学`,`随机化` | 中等 | | | 0385 | [迷你语法分析器](/solution/0300-0399/0385.Mini%20Parser/README.md) | `栈`,`深度优先搜索`,`字符串` | 中等 | | | 0386 | [字典序排数](/solution/0300-0399/0386.Lexicographical%20Numbers/README.md) | `深度优先搜索`,`字典树` | 中等 | | | 0387 | [字符串中的第一个唯一字符](/solution/0300-0399/0387.First%20Unique%20Character%20in%20a%20String/README.md) | `队列`,`哈希表`,`字符串`,`计数` | 简单 | | @@ -787,7 +787,7 @@ | 0774 | [最小化去加油站的最大距离](/solution/0700-0799/0774.Minimize%20Max%20Distance%20to%20Gas%20Station/README.md) | `数组`,`二分查找` | 困难 | 🔒 | | 0775 | [全局倒置与局部倒置](/solution/0700-0799/0775.Global%20and%20Local%20Inversions/README.md) | `数组`,`数学` | 中等 | | | 0776 | [拆分二叉搜索树](/solution/0700-0799/0776.Split%20BST/README.md) | `树`,`二叉搜索树`,`递归`,`二叉树` | 中等 | 🔒 | -| 0777 | [在LR字符串中交换相邻字符](/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README.md) | `双指针`,`字符串` | 中等 | | +| 0777 | [在 LR 字符串中交换相邻字符](/solution/0700-0799/0777.Swap%20Adjacent%20in%20LR%20String/README.md) | `双指针`,`字符串` | 中等 | | | 0778 | [水位上升的泳池中游泳](/solution/0700-0799/0778.Swim%20in%20Rising%20Water/README.md) | `深度优先搜索`,`广度优先搜索`,`并查集`,`数组`,`二分查找`,`矩阵`,`堆(优先队列)` | 困难 | | | 0779 | [第K个语法符号](/solution/0700-0799/0779.K-th%20Symbol%20in%20Grammar/README.md) | `位运算`,`递归`,`数学` | 中等 | | | 0780 | [到达终点](/solution/0700-0799/0780.Reaching%20Points/README.md) | `数学` | 困难 | | @@ -3363,6 +3363,7 @@ | 3350 | [检测相邻递增子数组 II](/solution/3300-3399/3350.Adjacent%20Increasing%20Subarrays%20Detection%20II/README.md) | `数组`,`二分查找` | 中等 | 第 423 场周赛 | | 3351 | [好子序列的元素之和](/solution/3300-3399/3351.Sum%20of%20Good%20Subsequences/README.md) | `数组`,`哈希表`,`动态规划` | 困难 | 第 423 场周赛 | | 3352 | [统计小于 N 的 K 可约简整数](/solution/3300-3399/3352.Count%20K-Reducible%20Numbers%20Less%20Than%20N/README.md) | `数学`,`字符串`,`动态规划`,`组合数学` | 困难 | 第 423 场周赛 | +| 3353 | [Minimum Total Operations](/solution/3300-3399/3353.Minimum%20Total%20Operations/README.md) | | 简单 | 🔒 | ## 版权 diff --git a/solution/README_EN.md b/solution/README_EN.md index 102754795d988..5f9c1a3f9f19b 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -392,7 +392,7 @@ Press Control + F(or Command + F on | 0381 | [Insert Delete GetRandom O(1) - Duplicates allowed](/solution/0300-0399/0381.Insert%20Delete%20GetRandom%20O%281%29%20-%20Duplicates%20allowed/README_EN.md) | `Design`,`Array`,`Hash Table`,`Math`,`Randomized` | Hard | | | 0382 | [Linked List Random Node](/solution/0300-0399/0382.Linked%20List%20Random%20Node/README_EN.md) | `Reservoir Sampling`,`Linked List`,`Math`,`Randomized` | Medium | | | 0383 | [Ransom Note](/solution/0300-0399/0383.Ransom%20Note/README_EN.md) | `Hash Table`,`String`,`Counting` | Easy | | -| 0384 | [Shuffle an Array](/solution/0300-0399/0384.Shuffle%20an%20Array/README_EN.md) | `Array`,`Math`,`Randomized` | Medium | | +| 0384 | [Shuffle an Array](/solution/0300-0399/0384.Shuffle%20an%20Array/README_EN.md) | `Design`,`Array`,`Math`,`Randomized` | Medium | | | 0385 | [Mini Parser](/solution/0300-0399/0385.Mini%20Parser/README_EN.md) | `Stack`,`Depth-First Search`,`String` | Medium | | | 0386 | [Lexicographical Numbers](/solution/0300-0399/0386.Lexicographical%20Numbers/README_EN.md) | `Depth-First Search`,`Trie` | Medium | | | 0387 | [First Unique Character in a String](/solution/0300-0399/0387.First%20Unique%20Character%20in%20a%20String/README_EN.md) | `Queue`,`Hash Table`,`String`,`Counting` | Easy | | @@ -3361,6 +3361,7 @@ Press Control + F(or Command + F on | 3350 | [Adjacent Increasing Subarrays Detection II](/solution/3300-3399/3350.Adjacent%20Increasing%20Subarrays%20Detection%20II/README_EN.md) | `Array`,`Binary Search` | Medium | Weekly Contest 423 | | 3351 | [Sum of Good Subsequences](/solution/3300-3399/3351.Sum%20of%20Good%20Subsequences/README_EN.md) | `Array`,`Hash Table`,`Dynamic Programming` | Hard | Weekly Contest 423 | | 3352 | [Count K-Reducible Numbers Less Than N](/solution/3300-3399/3352.Count%20K-Reducible%20Numbers%20Less%20Than%20N/README_EN.md) | `Math`,`String`,`Dynamic Programming`,`Combinatorics` | Hard | Weekly Contest 423 | +| 3353 | [Minimum Total Operations](/solution/3300-3399/3353.Minimum%20Total%20Operations/README_EN.md) | | Easy | 🔒 | ## Copyright