Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2cbc8f3

Browse files
authored
feat: add weekly contest 374 (doocs#2056)
1 parent 8bf5ff8 commit 2cbc8f3

File tree

14 files changed

+743
-0
lines changed

14 files changed

+743
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# [2951. 找出峰值](https://leetcode.cn/problems/find-the-peaks)
2+
3+
[English Version](/solution/2900-2999/2951.Find%20the%20Peaks/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从 <strong>0</strong> 开始的数组 <code>mountain</code> 。你的任务是找出数组&nbsp;<code>mountain</code> 中的所有 <strong>峰值</strong>。</p>
10+
11+
<p>以数组形式返回给定数组中 <strong>峰值</strong> 的下标,<strong>顺序不限</strong> 。</p>
12+
13+
<p><strong>注意:</strong></p>
14+
15+
<ul>
16+
<li><strong>峰值</strong> 是指一个严格大于其相邻元素的元素。</li>
17+
<li>数组的第一个和最后一个元素 <strong>不</strong> 是峰值。</li>
18+
</ul>
19+
20+
<p>&nbsp;</p>
21+
22+
<p><strong class="example">示例 1:</strong></p>
23+
24+
<pre>
25+
<strong>输入:</strong>mountain = [2,4,4]
26+
<strong>输出:</strong>[]
27+
<strong>解释:</strong>mountain[0] 和 mountain[2] 不可能是峰值,因为它们是数组的第一个和最后一个元素。
28+
mountain[1] 也不可能是峰值,因为它不严格大于 mountain[2] 。
29+
因此,答案为 [] 。
30+
</pre>
31+
32+
<p><strong class="example">示例 2:</strong></p>
33+
34+
<pre>
35+
<strong>输入:</strong>mountain = [1,4,3,8,5]
36+
<strong>输出:</strong>[1,3]
37+
<strong>解释:</strong>mountain[0] 和 mountain[4] 不可能是峰值,因为它们是数组的第一个和最后一个元素。
38+
mountain[2] 也不可能是峰值,因为它不严格大于 mountain[3] 和 mountain[1] 。
39+
但是 mountain[1] 和 mountain[3] 严格大于它们的相邻元素。
40+
因此,答案是 [1,3] 。
41+
</pre>
42+
43+
<p>&nbsp;</p>
44+
45+
<p><strong>提示:</strong></p>
46+
47+
<ul>
48+
<li><code>3 &lt;= mountain.length &lt;= 100</code></li>
49+
<li><code>1 &lt;= mountain[i] &lt;= 100</code></li>
50+
</ul>
51+
52+
## 解法
53+
54+
<!-- 这里可写通用的实现逻辑 -->
55+
56+
<!-- tabs:start -->
57+
58+
### **Python3**
59+
60+
<!-- 这里可写当前语言的特殊实现逻辑 -->
61+
62+
```python
63+
64+
```
65+
66+
### **Java**
67+
68+
<!-- 这里可写当前语言的特殊实现逻辑 -->
69+
70+
```java
71+
72+
```
73+
74+
### **C++**
75+
76+
```cpp
77+
78+
```
79+
80+
### **Go**
81+
82+
```go
83+
84+
```
85+
86+
### **...**
87+
88+
```
89+
90+
```
91+
92+
<!-- tabs:end -->
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# [2951. Find the Peaks](https://leetcode.com/problems/find-the-peaks)
2+
3+
[中文文档](/solution/2900-2999/2951.Find%20the%20Peaks/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> array <code>mountain</code>. Your task is to find all the <strong>peaks</strong> in the <code>mountain</code> array.</p>
8+
9+
<p>Return <em>an array that consists of </em>indices<!-- notionvc: c9879de8-88bd-43b0-8224-40c4bee71cd6 --><em> of <strong>peaks</strong> in the given array in <strong>any order</strong>.</em></p>
10+
11+
<p><strong>Notes:</strong></p>
12+
13+
<ul>
14+
<li>A <strong>peak</strong> is defined as an element that is <strong>strictly greater</strong> than its neighboring elements.</li>
15+
<li>The first and last elements of the array are <strong>not</strong> a peak.</li>
16+
</ul>
17+
18+
<p>&nbsp;</p>
19+
<p><strong class="example">Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> mountain = [2,4,4]
23+
<strong>Output:</strong> []
24+
<strong>Explanation:</strong> mountain[0] and mountain[2] can not be a peak because they are first and last elements of the array.
25+
mountain[1] also can not be a peak because it is not strictly greater than mountain[2].
26+
So the answer is [].
27+
</pre>
28+
29+
<p><strong class="example">Example 2:</strong></p>
30+
31+
<pre>
32+
<strong>Input:</strong> mountain = [1,4,3,8,5]
33+
<strong>Output:</strong> [1,3]
34+
<strong>Explanation:</strong> mountain[0] and mountain[4] can not be a peak because they are first and last elements of the array.
35+
mountain[2] also can not be a peak because it is not strictly greater than mountain[3] and mountain[1].
36+
But mountain [1] and mountain[3] are strictly greater than their neighboring elements.
37+
So the answer is [1,3].
38+
</pre>
39+
40+
<p>&nbsp;</p>
41+
<p><strong>Constraints:</strong></p>
42+
43+
<ul>
44+
<li><code>3 &lt;= mountain.length &lt;= 100</code></li>
45+
<li><code>1 &lt;= mountain[i] &lt;= 100</code></li>
46+
</ul>
47+
48+
## Solutions
49+
50+
<!-- tabs:start -->
51+
52+
### **Python3**
53+
54+
```python
55+
56+
```
57+
58+
### **Java**
59+
60+
```java
61+
62+
```
63+
64+
### **C++**
65+
66+
```cpp
67+
68+
```
69+
70+
### **Go**
71+
72+
```go
73+
74+
```
75+
76+
### **...**
77+
78+
```
79+
80+
```
81+
82+
<!-- tabs:end -->
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# [2952. 需要添加的硬币的最小数量](https://leetcode.cn/problems/minimum-number-of-coins-to-be-added)
2+
3+
[English Version](/solution/2900-2999/2952.Minimum%20Number%20of%20Coins%20to%20be%20Added/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从 <strong>0 </strong>开始的整数数组 <code>coins</code>,表示可用的硬币的面值,以及一个整数 <code>target</code> 。</p>
10+
11+
<p>如果存在某个 <code>coins</code> 的子序列总和为 <code>x</code>,那么整数 <code>x</code> 就是一个 <strong>可取得的金额 </strong>。</p>
12+
13+
<p>返回需要添加到数组中的<strong> 任意面值 </strong>硬币的 <strong>最小数量 </strong>,使范围 <code>[1, target]</code> 内的每个整数都属于 <strong>可取得的金额</strong> 。</p>
14+
15+
<p>数组的 <strong>子序列</strong> 是通过删除原始数组的一些(<strong>可能不删除</strong>)元素而形成的新的 <strong>非空</strong> 数组,删除过程不会改变剩余元素的相对位置。</p>
16+
17+
<p>&nbsp;</p>
18+
19+
<p><strong class="example">示例 1:</strong></p>
20+
21+
<pre>
22+
<strong>输入:</strong>coins = [1,4,10], target = 19
23+
<strong>输出:</strong>2
24+
<strong>解释:</strong>需要添加面值为 2 和 8 的硬币各一枚,得到硬币数组 [1,2,4,8,10] 。
25+
可以证明从 1 到 19 的所有整数都可由数组中的硬币组合得到,且需要添加到数组中的硬币数目最小为 2 。
26+
</pre>
27+
28+
<p><strong class="example">示例 2:</strong></p>
29+
30+
<pre>
31+
<strong>输入:</strong>coins = [1,4,10,5,7,19], target = 19
32+
<strong>输出:</strong>1
33+
<strong>解释:</strong>只需要添加一枚面值为 2 的硬币,得到硬币数组 [1,2,4,5,7,10,19] 。
34+
可以证明从 1 到 19 的所有整数都可由数组中的硬币组合得到,且需要添加到数组中的硬币数目最小为 1 。</pre>
35+
36+
<p><strong class="example">示例 3:</strong></p>
37+
38+
<pre>
39+
<strong>输入:</strong>coins = [1,1,1], target = 20
40+
<strong>输出:</strong>3
41+
<strong>解释:</strong>
42+
需要添加面值为 4 、8 和 16 的硬币各一枚,得到硬币数组 [1,1,1,4,8,16] 。
43+
可以证明从 1 到 20 的所有整数都可由数组中的硬币组合得到,且需要添加到数组中的硬币数目最小为 3 。</pre>
44+
45+
<p>&nbsp;</p>
46+
47+
<p><strong>提示:</strong></p>
48+
49+
<ul>
50+
<li><code>1 &lt;= target &lt;= 10<sup>5</sup></code></li>
51+
<li><code>1 &lt;= coins.length &lt;= 10<sup>5</sup></code></li>
52+
<li><code>1 &lt;= coins[i] &lt;= target</code></li>
53+
</ul>
54+
55+
## 解法
56+
57+
<!-- 这里可写通用的实现逻辑 -->
58+
59+
<!-- tabs:start -->
60+
61+
### **Python3**
62+
63+
<!-- 这里可写当前语言的特殊实现逻辑 -->
64+
65+
```python
66+
67+
```
68+
69+
### **Java**
70+
71+
<!-- 这里可写当前语言的特殊实现逻辑 -->
72+
73+
```java
74+
75+
```
76+
77+
### **C++**
78+
79+
```cpp
80+
81+
```
82+
83+
### **Go**
84+
85+
```go
86+
87+
```
88+
89+
### **...**
90+
91+
```
92+
93+
```
94+
95+
<!-- tabs:end -->
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [2952. Minimum Number of Coins to be Added](https://leetcode.com/problems/minimum-number-of-coins-to-be-added)
2+
3+
[中文文档](/solution/2900-2999/2952.Minimum%20Number%20of%20Coins%20to%20be%20Added/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> integer array <code>coins</code>, representing the values of the coins available, and an integer <code>target</code>.</p>
8+
9+
<p>An integer <code>x</code> is <strong>obtainable</strong> if there exists a subsequence of <code>coins</code> that sums to <code>x</code>.</p>
10+
11+
<p>Return <em>the<strong> minimum</strong> number of coins <strong>of any value</strong> that need to be added to the array so that every integer in the range</em> <code>[1, target]</code><em> is <strong>obtainable</strong></em>.</p>
12+
13+
<p>A <strong>subsequence</strong> of an array is a new <strong>non-empty</strong> array that is formed from the original array by deleting some (<strong>possibly none</strong>) of the elements without disturbing the relative positions of the remaining elements.</p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong class="example">Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> coins = [1,4,10], target = 19
20+
<strong>Output:</strong> 2
21+
<strong>Explanation:</strong> We need to add coins 2 and 8. The resulting array will be [1,2,4,8,10].
22+
It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 2 is the minimum number of coins that need to be added to the array.
23+
</pre>
24+
25+
<p><strong class="example">Example 2:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> coins = [1,4,10,5,7,19], target = 19
29+
<strong>Output:</strong> 1
30+
<strong>Explanation:</strong> We only need to add the coin 2. The resulting array will be [1,2,4,5,7,10,19].
31+
It can be shown that all integers from 1 to 19 are obtainable from the resulting array, and that 1 is the minimum number of coins that need to be added to the array.
32+
</pre>
33+
34+
<p><strong class="example">Example 3:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> coins = [1,1,1], target = 20
38+
<strong>Output:</strong> 3
39+
<strong>Explanation:</strong> We need to add coins 4, 8, and 16. The resulting array will be [1,1,1,4,8,16].
40+
It can be shown that all integers from 1 to 20 are obtainable from the resulting array, and that 3 is the minimum number of coins that need to be added to the array.
41+
</pre>
42+
43+
<p>&nbsp;</p>
44+
<p><strong>Constraints:</strong></p>
45+
46+
<ul>
47+
<li><code>1 &lt;= target &lt;= 10<sup>5</sup></code></li>
48+
<li><code>1 &lt;= coins.length &lt;= 10<sup>5</sup></code></li>
49+
<li><code>1 &lt;= coins[i] &lt;= target</code></li>
50+
</ul>
51+
52+
## Solutions
53+
54+
<!-- tabs:start -->
55+
56+
### **Python3**
57+
58+
```python
59+
60+
```
61+
62+
### **Java**
63+
64+
```java
65+
66+
```
67+
68+
### **C++**
69+
70+
```cpp
71+
72+
```
73+
74+
### **Go**
75+
76+
```go
77+
78+
```
79+
80+
### **...**
81+
82+
```
83+
84+
```
85+
86+
<!-- tabs:end -->

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /