Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update lc problems #1730

Merged
merged 1 commit into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: update lc problems
  • Loading branch information
yanglbme committed Oct 1, 2023
commit abc42c532058cc7aa1f9f941efe8c68acd6d3396
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# [2869. Minimum Operations to Collect Elements](https://leetcode.cn/problems/minimum-operations-to-collect-elements/)
# [2869. 收集元素的最少操作次数](https://leetcode.cn/problems/minimum-operations-to-collect-elements/)

[English Version](/solution/2800-2899/2869.Minimum%20Operations%20to%20Collect%20Elements/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

<p>给你一个正整数数组&nbsp;<code>nums</code>&nbsp;和一个整数&nbsp;<code>k</code>&nbsp;。</p>

<p>一次操作中,你可以将数组的最后一个元素删除,将该元素添加到一个集合中。</p>

<p>请你返回收集元素&nbsp;<code>1, 2, ..., k</code>&nbsp;需要的&nbsp;<strong>最少操作次数</strong>&nbsp;。</p>
Expand All @@ -14,21 +16,24 @@

<p><strong class="example">示例 1:</strong></p>

<pre><b>输入:</b>nums = [3,1,5,4,2], k = 2
<pre>
<b>输入:</b>nums = [3,1,5,4,2], k = 2
<b>输出:</b>4
<b>解释:</b>4 次操作后,集合中的元素依次添加了 2 ,4 ,5 和 1 。此时集合中包含元素 1 和 2 ,所以答案为 4 。
</pre>

<p><strong class="example">示例 2:</strong></p>

<pre><b>输入:</b>nums = [3,1,5,4,2], k = 5
<pre>
<b>输入:</b>nums = [3,1,5,4,2], k = 5
<b>输出:</b>5
<b>解释:</b>5 次操作后,集合中的元素依次添加了 2 ,4 ,5 ,1 和 3 。此时集合中包含元素 1 到 5 ,所以答案为 5 。
</pre>

<p><strong class="example">示例 3:</strong></p>

<pre><b>输入:</b>nums = [3,2,5,3,1], k = 3
<pre>
<b>输入:</b>nums = [3,2,5,3,1], k = 3
<b>输出:</b>4
<b>解释:</b>4 次操作后,集合中的元素依次添加了 1 ,3 ,5 和 2 。此时集合中包含元素 1 到 3 ,所以答案为 4 。
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@

## Description

<p>You are given an array <code>nums</code> of positive integers and an integer <code>k</code>.</p>

<p>In one operation, you can remove the last element of the array and add it to your collection.</p>

<p>Return <em>the <strong>minimum number of operations</strong> needed to collect elements</em> <code>1, 2, ..., k</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre><strong>Input:</strong> nums = [3,1,5,4,2], k = 2
<pre>
<strong>Input:</strong> nums = [3,1,5,4,2], k = 2
<strong>Output:</strong> 4
<strong>Explanation:</strong> After 4 operations, we collect elements 2, 4, 5, and 1, in this order. Our collection contains elements 1 and 2. Hence, the answer is 4.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre><strong>Input:</strong> nums = [3,1,5,4,2], k = 5
<pre>
<strong>Input:</strong> nums = [3,1,5,4,2], k = 5
<strong>Output:</strong> 5
<strong>Explanation:</strong> After 5 operations, we collect elements 2, 4, 5, 1, and 3, in this order. Our collection contains elements 1 through 5. Hence, the answer is 5.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre><strong>Input:</strong> nums = [3,2,5,3,1], k = 3
<pre>
<strong>Input:</strong> nums = [3,2,5,3,1], k = 3
<strong>Output:</strong> 4
<strong>Explanation:</strong> After 4 operations, we collect elements 1, 3, 5, and 2, in this order. Our collection contains elements 1 through 3. Hence, the answer is 4.
</pre>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# [2870. Minimum Number of Operations to Make Array Empty](https://leetcode.cn/problems/minimum-number-of-operations-to-make-array-empty/)
# [2870. 使数组为空的最少操作次数](https://leetcode.cn/problems/minimum-number-of-operations-to-make-array-empty/)

[English Version](/solution/2800-2899/2870.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20Empty/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

<p>给你一个下标从 <strong>0</strong>&nbsp;开始的正整数数组&nbsp;<code>nums</code>&nbsp;。</p>

<p>你可以对数组执行以下两种操作 <strong>任意次</strong>&nbsp;:</p>

<ul>
Expand All @@ -19,7 +21,8 @@

<p><strong class="example">示例 1:</strong></p>

<pre><strong>输入:</strong>nums = [2,3,3,2,2,4,2,3,4]
<pre>
<strong>输入:</strong>nums = [2,3,3,2,2,4,2,3,4]
<b>输出:</b>4
<b>解释:</b>我们可以执行以下操作使数组为空:
- 对下标为 0 和 3 的元素执行第一种操作,得到 nums = [3,3,2,4,2,3,4] 。
Expand All @@ -31,7 +34,8 @@

<p><strong class="example">示例 2:</strong></p>

<pre><b>输入:</b>nums = [2,1,2,2,3,3]
<pre>
<b>输入:</b>nums = [2,1,2,2,3,3]
<b>输出:</b>-1
<b>解释:</b>无法使数组为空。
</pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## Description

<p>You are given a <strong>0-indexed</strong> array <code>nums</code> consisting of positive integers.</p>

<p>There are two types of operations that you can apply on the array <strong>any</strong> number of times:</p>

<ul>
Expand All @@ -16,7 +18,8 @@
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre><strong>Input:</strong> nums = [2,3,3,2,2,4,2,3,4]
<pre>
<strong>Input:</strong> nums = [2,3,3,2,2,4,2,3,4]
<strong>Output:</strong> 4
<strong>Explanation:</strong> We can apply the following operations to make the array empty:
- Apply the first operation on the elements at indices 0 and 3. The resulting array is nums = [3,3,2,4,2,3,4].
Expand All @@ -28,7 +31,8 @@ It can be shown that we cannot make the array empty in less than 4 operations.

<p><strong class="example">Example 2:</strong></p>

<pre><strong>Input:</strong> nums = [2,1,2,2,3,3]
<pre>
<strong>Input:</strong> nums = [2,1,2,2,3,3]
<strong>Output:</strong> -1
<strong>Explanation:</strong> It is impossible to empty the array.
</pre>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# [2871. Split Array Into Maximum Number of Subarrays](https://leetcode.cn/problems/split-array-into-maximum-number-of-subarrays/)
# [2871. 将数组分割成最多数目的子数组](https://leetcode.cn/problems/split-array-into-maximum-number-of-subarrays/)

[English Version](/solution/2800-2899/2871.Split%20Array%20Into%20Maximum%20Number%20of%20Subarrays/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

<p>给你一个只包含 <strong>非负</strong>&nbsp;整数的数组&nbsp;<code>nums</code>&nbsp;。</p>

<p>我们定义满足 <code>l &lt;= r</code>&nbsp;的子数组&nbsp;<code>nums[l..r]</code>&nbsp;的分数为&nbsp;<code>nums[l] AND nums[l + 1] AND ... AND nums[r]</code>&nbsp;,其中&nbsp;<strong>AND</strong>&nbsp;是按位与运算。</p>

<p>请你将数组分割成一个或者更多子数组,满足:</p>
Expand All @@ -23,7 +25,8 @@

<p><strong class="example">示例 1:</strong></p>

<pre><b>输入:</b>nums = [1,0,2,0,1,2]
<pre>
<b>输入:</b>nums = [1,0,2,0,1,2]
<b>输出:</b>3
<strong>解释:</strong>我们可以将数组分割成以下子数组:
- [1,0] 。子数组分数为 1 AND 0 = 0 。
Expand All @@ -35,7 +38,8 @@

<p><strong class="example">示例 2:</strong></p>

<pre><b>输入:</b>nums = [5,7,1,3]
<pre>
<b>输入:</b>nums = [5,7,1,3]
<b>输出:</b>1
<b>解释:</b>我们可以将数组分割成一个子数组:[5,7,1,3] ,分数为 1 ,这是可以得到的最小总分数。
在总分数为 1 的前提下,最多可以将数组分割成 1 个子数组。所以返回 1 。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## Description

<p>You are given an array <code>nums</code> consisting of <strong>non-negative</strong> integers.</p>

<p>We define the score of subarray <code>nums[l..r]</code> such that <code>l &lt;= r</code> as <code>nums[l] AND nums[l + 1] AND ... AND nums[r]</code> where <strong>AND</strong> is the bitwise <code>AND</code> operation.</p>

<p>Consider splitting the array into one or more subarrays such that the following conditions are satisfied:</p>
Expand All @@ -20,7 +22,8 @@
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre><strong>Input:</strong> nums = [1,0,2,0,1,2]
<pre>
<strong>Input:</strong> nums = [1,0,2,0,1,2]
<strong>Output:</strong> 3
<strong>Explanation:</strong> We can split the array into the following subarrays:
- [1,0]. The score of this subarray is 1 AND 0 = 0.
Expand All @@ -32,7 +35,8 @@ It can be shown that we cannot split the array into more than 3 subarrays with a

<p><strong class="example">Example 2:</strong></p>

<pre><strong>Input:</strong> nums = [5,7,1,3]
<pre>
<strong>Input:</strong> nums = [5,7,1,3]
<strong>Output:</strong> 1
<strong>Explanation:</strong> We can split the array into one subarray: [5,7,1,3] with a score of 1, which is the minimum possible score that we can obtain.
It can be shown that we cannot split the array into more than 1 subarray with a total score of 1. So we return 1.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# [2872. Maximum Number of K-Divisible Components](https://leetcode.com/problems/maximum-number-of-k-divisible-components/)
# [2872. 可以被 K 整除连通块的最大数目](https://leetcode.com/problems/maximum-number-of-k-divisible-components/)

[English Version](/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/README_EN.md)

Expand All @@ -18,9 +18,10 @@

<p><strong class="example">示例 1:</strong></p>

<p><img alt="" src="./images/example1.jpg" style="width: 1024px; height: 453px;"></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/images/example12-cropped2svg.jpg" style="width: 1024px; height: 453px;" /></p>

<pre><b>输入:</b>n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6
<pre>
<b>输入:</b>n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6
<b>输出:</b>2
<b>解释:</b>我们删除节点 1 和 2 之间的边。这是一个合法分割,因为:
- 节点 1 和 3 所在连通块的值为 values[1] + values[3] = 12 。
Expand All @@ -29,9 +30,10 @@

<p><strong class="example">示例 2:</strong></p>

<p><img alt="" src="./images/example2.jpg" style="width: 999px; height: 338px;"></p>
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/images/example21svg-1.jpg" style="width: 999px; height: 338px;" /></p>

<pre><b>输入:</b>n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3
<pre>
<b>输入:</b>n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3
<b>输出:</b>3
<b>解释:</b>我们删除节点 0 和 2 ,以及节点 0 和 1 之间的边。这是一个合法分割,因为:
- 节点 0 的连通块的值为 values[0] = 3 。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="./images/example1.jpg" style="width: 1024px; height: 453px;">
<pre><strong>Input:</strong> n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/images/example12-cropped2svg.jpg" style="width: 1024px; height: 453px;" />
<pre>
<strong>Input:</strong> n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6
<strong>Output:</strong> 2
<strong>Explanation:</strong> We remove the edge connecting node 1 with 2. The resulting split is valid because:
- The value of the component containing nodes 1 and 3 is values[1] + values[3] = 12.
- The value of the component containing nodes 0, 2, and 4 is values[0] + values[2] + values[4] = 6.
It can be shown that no other valid split has more than 2 connected components.</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="./images/example2.jpg" style="width: 999px; height: 338px;">
<pre><strong>Input:</strong> n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/images/example21svg-1.jpg" style="width: 999px; height: 338px;" />
<pre>
<strong>Input:</strong> n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3
<strong>Output:</strong> 3
<strong>Explanation:</strong> We remove the edge connecting node 0 with 2, and the edge connecting node 0 with 1. The resulting split is valid because:
- The value of the component containing node 0 is values[0] = 3.
Expand Down
7 changes: 7 additions & 0 deletions solution/CONTEST_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

## 往期竞赛

#### 第 114 场双周赛(2023-09-30 22:30, 90 分钟) 参赛人数 2406

- [2869. 收集元素的最少操作次数](/solution/2800-2899/2869.Minimum%20Operations%20to%20Collect%20Elements/README.md)
- [2870. 使数组为空的最少操作次数](/solution/2800-2899/2870.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20Empty/README.md)
- [2871. 将数组分割成最多数目的子数组](/solution/2800-2899/2871.Split%20Array%20Into%20Maximum%20Number%20of%20Subarrays/README.md)
- [2872. 可以被 K 整除连通块的最大数目](/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/README.md)

#### 第 364 场周赛(2023-09-24 10:30, 90 分钟) 参赛人数 4304

- [2864. 最大二进制奇数](/solution/2800-2899/2864.Maximum%20Odd%20Binary%20Number/README.md)
Expand Down
7 changes: 7 additions & 0 deletions solution/CONTEST_README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ Get your rating changes right after the completion of LeetCode contests, https:/

## Past Contests

#### Biweekly Contest 114

- [2869. Minimum Operations to Collect Elements](/solution/2800-2899/2869.Minimum%20Operations%20to%20Collect%20Elements/README_EN.md)
- [2870. Minimum Number of Operations to Make Array Empty](/solution/2800-2899/2870.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20Empty/README_EN.md)
- [2871. Split Array Into Maximum Number of Subarrays](/solution/2800-2899/2871.Split%20Array%20Into%20Maximum%20Number%20of%20Subarrays/README_EN.md)
- [2872. Maximum Number of K-Divisible Components](/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/README_EN.md)

#### Weekly Contest 364

- [2864. Maximum Odd Binary Number](/solution/2800-2899/2864.Maximum%20Odd%20Binary%20Number/README_EN.md)
Expand Down
4 changes: 4 additions & 0 deletions solution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2879,6 +2879,10 @@
| 2866 | [美丽塔 II](/solution/2800-2899/2866.Beautiful%20Towers%20II/README.md) | `栈`,`数组`,`单调栈` | 中等 | 第 364 场周赛 |
| 2867 | [统计树中的合法路径数目](/solution/2800-2899/2867.Count%20Valid%20Paths%20in%20a%20Tree/README.md) | `树`,`深度优先搜索`,`数学`,`动态规划`,`数论` | 困难 | 第 364 场周赛 |
| 2868 | [单词游戏](/solution/2800-2899/2868.The%20Wording%20Game/README.md) | | 困难 | 🔒 |
| 2869 | [收集元素的最少操作次数](/solution/2800-2899/2869.Minimum%20Operations%20to%20Collect%20Elements/README.md) | | 简单 | 第 114 场双周赛 |
| 2870 | [使数组为空的最少操作次数](/solution/2800-2899/2870.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20Empty/README.md) | | 中等 | 第 114 场双周赛 |
| 2871 | [将数组分割成最多数目的子数组](/solution/2800-2899/2871.Split%20Array%20Into%20Maximum%20Number%20of%20Subarrays/README.md) | | 中等 | 第 114 场双周赛 |
| 2872 | [可以被 K 整除连通块的最大数目](/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/README.md) | | 困难 | 第 114 场双周赛 |

## 版权

Expand Down
4 changes: 4 additions & 0 deletions solution/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,10 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
| 2866 | [Beautiful Towers II](/solution/2800-2899/2866.Beautiful%20Towers%20II/README_EN.md) | `Stack`,`Array`,`Monotonic Stack` | Medium | Weekly Contest 364 |
| 2867 | [Count Valid Paths in a Tree](/solution/2800-2899/2867.Count%20Valid%20Paths%20in%20a%20Tree/README_EN.md) | `Tree`,`Depth-First Search`,`Math`,`Dynamic Programming`,`Number Theory` | Hard | Weekly Contest 364 |
| 2868 | [The Wording Game](/solution/2800-2899/2868.The%20Wording%20Game/README_EN.md) | | Hard | 🔒 |
| 2869 | [Minimum Operations to Collect Elements](/solution/2800-2899/2869.Minimum%20Operations%20to%20Collect%20Elements/README_EN.md) | | Easy | Biweekly Contest 114 |
| 2870 | [Minimum Number of Operations to Make Array Empty](/solution/2800-2899/2870.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20Empty/README_EN.md) | | Medium | Biweekly Contest 114 |
| 2871 | [Split Array Into Maximum Number of Subarrays](/solution/2800-2899/2871.Split%20Array%20Into%20Maximum%20Number%20of%20Subarrays/README_EN.md) | | Medium | Biweekly Contest 114 |
| 2872 | [Maximum Number of K-Divisible Components](/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/README_EN.md) | | Hard | Biweekly Contest 114 |

## Copyright

Expand Down
4 changes: 4 additions & 0 deletions solution/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -2924,3 +2924,7 @@
- [2866.美丽塔 II](/solution/2800-2899/2866.Beautiful%20Towers%20II/README.md)
- [2867.统计树中的合法路径数目](/solution/2800-2899/2867.Count%20Valid%20Paths%20in%20a%20Tree/README.md)
- [2868.单词游戏](/solution/2800-2899/2868.The%20Wording%20Game/README.md)
- [2869.收集元素的最少操作次数](/solution/2800-2899/2869.Minimum%20Operations%20to%20Collect%20Elements/README.md)
- [2870.使数组为空的最少操作次数](/solution/2800-2899/2870.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20Empty/README.md)
- [2871.将数组分割成最多数目的子数组](/solution/2800-2899/2871.Split%20Array%20Into%20Maximum%20Number%20of%20Subarrays/README.md)
- [2872.可以被 K 整除连通块的最大数目](/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/README.md)
4 changes: 4 additions & 0 deletions solution/summary_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -2924,3 +2924,7 @@
- [2866.Beautiful Towers II](/solution/2800-2899/2866.Beautiful%20Towers%20II/README_EN.md)
- [2867.Count Valid Paths in a Tree](/solution/2800-2899/2867.Count%20Valid%20Paths%20in%20a%20Tree/README_EN.md)
- [2868.The Wording Game](/solution/2800-2899/2868.The%20Wording%20Game/README_EN.md)
- [2869.Minimum Operations to Collect Elements](/solution/2800-2899/2869.Minimum%20Operations%20to%20Collect%20Elements/README_EN.md)
- [2870.Minimum Number of Operations to Make Array Empty](/solution/2800-2899/2870.Minimum%20Number%20of%20Operations%20to%20Make%20Array%20Empty/README_EN.md)
- [2871.Split Array Into Maximum Number of Subarrays](/solution/2800-2899/2871.Split%20Array%20Into%20Maximum%20Number%20of%20Subarrays/README_EN.md)
- [2872.Maximum Number of K-Divisible Components](/solution/2800-2899/2872.Maximum%20Number%20of%20K-Divisible%20Components/README_EN.md)