Skip to content

Commit 66f8ec0

Browse files
authored
feat: add new lc problem (doocs#2133)
1 parent 6614109 commit 66f8ec0

File tree

6 files changed

+192
-0
lines changed

6 files changed

+192
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# [2969. Minimum Number of Coins for Fruits II](https://leetcode.cn/problems/minimum-number-of-coins-for-fruits-ii)
2+
3+
[English Version](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>You are at a fruit market with different types of exotic fruits on display.</p>
10+
11+
<p>You are given a <strong>1-indexed</strong> array <code>prices</code>, where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
12+
13+
<p>The fruit market has the following offer:</p>
14+
15+
<ul>
16+
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[i]</code> coins, you can get the next <code>i</code> fruits for free.</li>
17+
</ul>
18+
19+
<p><strong>Note</strong> that even if you <strong>can</strong> take fruit <code>j</code> for free, you can still purchase it for <code>prices[j]</code> coins to receive a new offer.</p>
20+
21+
<p>Return <em>the <strong>minimum</strong> number of coins needed to acquire all the fruits</em>.</p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong class="example">Example 1:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> prices = [3,1,2]
28+
<strong>Output:</strong> 4
29+
<strong>Explanation:</strong> You can acquire the fruits as follows:
30+
- Purchase the 1<sup>st</sup> fruit with 3 coins, and you are allowed to take the 2<sup>nd</sup> fruit for free.
31+
- Purchase the 2<sup>nd</sup> fruit with 1 coin, and you are allowed to take the 3<sup>rd</sup> fruit for free.
32+
- Take the 3<sup>rd</sup> fruit for free.
33+
Note that even though you were allowed to take the 2<sup>nd</sup> fruit for free, you purchased it because it is more optimal.
34+
It can be proven that 4 is the minimum number of coins needed to acquire all the fruits.
35+
</pre>
36+
37+
<p><strong class="example">Example 2:</strong></p>
38+
39+
<pre>
40+
<strong>Input:</strong> prices = [1,10,1,1]
41+
<strong>Output:</strong> 2
42+
<strong>Explanation:</strong> You can acquire the fruits as follows:
43+
- Purchase the 1<sup>st</sup> fruit with 1 coin, and you are allowed to take the 2<sup>nd</sup> fruit for free.
44+
- Take the 2<sup>nd</sup> fruit for free.
45+
- Purchase the 3<sup>rd</sup> fruit for 1 coin, and you are allowed to take the 4<sup>th</sup> fruit for free.
46+
- Take the 4<sup>t</sup><sup>h</sup> fruit for free.
47+
It can be proven that 2 is the minimum number of coins needed to acquire all the fruits.
48+
</pre>
49+
50+
<p>&nbsp;</p>
51+
<p><strong>Constraints:</strong></p>
52+
53+
<ul>
54+
<li><code>1 &lt;= prices.length &lt;= 10<sup>5</sup></code></li>
55+
<li><code>1 &lt;= prices[i] &lt;= 10<sup>5</sup></code></li>
56+
</ul>
57+
58+
## 解法
59+
60+
<!-- 这里可写通用的实现逻辑 -->
61+
62+
<!-- tabs:start -->
63+
64+
### **Python3**
65+
66+
<!-- 这里可写当前语言的特殊实现逻辑 -->
67+
68+
```python
69+
70+
```
71+
72+
### **Java**
73+
74+
<!-- 这里可写当前语言的特殊实现逻辑 -->
75+
76+
```java
77+
78+
```
79+
80+
### **C++**
81+
82+
```cpp
83+
84+
```
85+
86+
### **Go**
87+
88+
```go
89+
90+
```
91+
92+
### **...**
93+
94+
```
95+
96+
```
97+
98+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# [2969. Minimum Number of Coins for Fruits II](https://leetcode.com/problems/minimum-number-of-coins-for-fruits-ii)
2+
3+
[中文文档](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README.md)
4+
5+
## Description
6+
7+
<p>You are at a fruit market with different types of exotic fruits on display.</p>
8+
9+
<p>You are given a <strong>1-indexed</strong> array <code>prices</code>, where <code>prices[i]</code> denotes the number of coins needed to purchase the <code>i<sup>th</sup></code> fruit.</p>
10+
11+
<p>The fruit market has the following offer:</p>
12+
13+
<ul>
14+
<li>If you purchase the <code>i<sup>th</sup></code> fruit at <code>prices[i]</code> coins, you can get the next <code>i</code> fruits for free.</li>
15+
</ul>
16+
17+
<p><strong>Note</strong> that even if you <strong>can</strong> take fruit <code>j</code> for free, you can still purchase it for <code>prices[j]</code> coins to receive a new offer.</p>
18+
19+
<p>Return <em>the <strong>minimum</strong> number of coins needed to acquire all the fruits</em>.</p>
20+
21+
<p>&nbsp;</p>
22+
<p><strong class="example">Example 1:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> prices = [3,1,2]
26+
<strong>Output:</strong> 4
27+
<strong>Explanation:</strong> You can acquire the fruits as follows:
28+
- Purchase the 1<sup>st</sup> fruit with 3 coins, and you are allowed to take the 2<sup>nd</sup> fruit for free.
29+
- Purchase the 2<sup>nd</sup> fruit with 1 coin, and you are allowed to take the 3<sup>rd</sup> fruit for free.
30+
- Take the 3<sup>rd</sup> fruit for free.
31+
Note that even though you were allowed to take the 2<sup>nd</sup> fruit for free, you purchased it because it is more optimal.
32+
It can be proven that 4 is the minimum number of coins needed to acquire all the fruits.
33+
</pre>
34+
35+
<p><strong class="example">Example 2:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong> prices = [1,10,1,1]
39+
<strong>Output:</strong> 2
40+
<strong>Explanation:</strong> You can acquire the fruits as follows:
41+
- Purchase the 1<sup>st</sup> fruit with 1 coin, and you are allowed to take the 2<sup>nd</sup> fruit for free.
42+
- Take the 2<sup>nd</sup> fruit for free.
43+
- Purchase the 3<sup>rd</sup> fruit for 1 coin, and you are allowed to take the 4<sup>th</sup> fruit for free.
44+
- Take the 4<sup>t</sup><sup>h</sup> fruit for free.
45+
It can be proven that 2 is the minimum number of coins needed to acquire all the fruits.
46+
</pre>
47+
48+
<p>&nbsp;</p>
49+
<p><strong>Constraints:</strong></p>
50+
51+
<ul>
52+
<li><code>1 &lt;= prices.length &lt;= 10<sup>5</sup></code></li>
53+
<li><code>1 &lt;= prices[i] &lt;= 10<sup>5</sup></code></li>
54+
</ul>
55+
56+
## Solutions
57+
58+
<!-- tabs:start -->
59+
60+
### **Python3**
61+
62+
```python
63+
64+
```
65+
66+
### **Java**
67+
68+
```java
69+
70+
```
71+
72+
### **C++**
73+
74+
```cpp
75+
76+
```
77+
78+
### **Go**
79+
80+
```go
81+
82+
```
83+
84+
### **...**
85+
86+
```
87+
88+
```
89+
90+
<!-- tabs:end -->

solution/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -2979,6 +2979,7 @@
29792979
| 2966 | [划分数组并满足最大差限制](/solution/2900-2999/2966.Divide%20Array%20Into%20Arrays%20With%20Max%20Difference/README.md) | | 中等 | 第 376 场周赛 |
29802980
| 2967 | [使数组成为等数数组的最小代价](/solution/2900-2999/2967.Minimum%20Cost%20to%20Make%20Array%20Equalindromic/README.md) | | 中等 | 第 376 场周赛 |
29812981
| 2968 | [执行操作使频率分数最大](/solution/2900-2999/2968.Apply%20Operations%20to%20Maximize%20Frequency%20Score/README.md) | | 困难 | 第 376 场周赛 |
2982+
| 2969 | [Minimum Number of Coins for Fruits II](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README.md) | | 困难 | 🔒 |
29822983

29832984
## 版权
29842985

solution/README_EN.md

+1
Original file line numberDiff line numberDiff line change
@@ -2977,6 +2977,7 @@ Press <kbd>Control</kbd> + <kbd>F</kbd>(or <kbd>Command</kbd> + <kbd>F</kbd> on
29772977
| 2966 | [Divide Array Into Arrays With Max Difference](/solution/2900-2999/2966.Divide%20Array%20Into%20Arrays%20With%20Max%20Difference/README_EN.md) | | Medium | Weekly Contest 376 |
29782978
| 2967 | [Minimum Cost to Make Array Equalindromic](/solution/2900-2999/2967.Minimum%20Cost%20to%20Make%20Array%20Equalindromic/README_EN.md) | | Medium | Weekly Contest 376 |
29792979
| 2968 | [Apply Operations to Maximize Frequency Score](/solution/2900-2999/2968.Apply%20Operations%20to%20Maximize%20Frequency%20Score/README_EN.md) | | Hard | Weekly Contest 376 |
2980+
| 2969 | [Minimum Number of Coins for Fruits II](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README_EN.md) | | Hard | 🔒 |
29802981

29812982
## Copyright
29822983

solution/summary.md

+1
Original file line numberDiff line numberDiff line change
@@ -3026,3 +3026,4 @@
30263026
- [2966.划分数组并满足最大差限制](/solution/2900-2999/2966.Divide%20Array%20Into%20Arrays%20With%20Max%20Difference/README.md)
30273027
- [2967.使数组成为等数数组的最小代价](/solution/2900-2999/2967.Minimum%20Cost%20to%20Make%20Array%20Equalindromic/README.md)
30283028
- [2968.执行操作使频率分数最大](/solution/2900-2999/2968.Apply%20Operations%20to%20Maximize%20Frequency%20Score/README.md)
3029+
- [2969.Minimum Number of Coins for Fruits II](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README.md)

solution/summary_en.md

+1
Original file line numberDiff line numberDiff line change
@@ -3026,3 +3026,4 @@
30263026
- [2966.Divide Array Into Arrays With Max Difference](/solution/2900-2999/2966.Divide%20Array%20Into%20Arrays%20With%20Max%20Difference/README_EN.md)
30273027
- [2967.Minimum Cost to Make Array Equalindromic](/solution/2900-2999/2967.Minimum%20Cost%20to%20Make%20Array%20Equalindromic/README_EN.md)
30283028
- [2968.Apply Operations to Maximize Frequency Score](/solution/2900-2999/2968.Apply%20Operations%20to%20Maximize%20Frequency%20Score/README_EN.md)
3029+
- [2969.Minimum Number of Coins for Fruits II](/solution/2900-2999/2969.Minimum%20Number%20of%20Coins%20for%20Fruits%20II/README_EN.md)

0 commit comments

Comments
 (0)