Skip to content

Commit 1372a44

Browse files
committed
feat: add solutions to lc problems: No.2103~2106
* No.2103.Rings and Rods * No.2104.Sum of Subarray Ranges * No.2105.Watering Plants II * No.2106.Maximum Fruits Harvested After at Most K Steps
1 parent 3ed2d9d commit 1372a44

File tree

44 files changed

+2728
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2728
-27
lines changed

.github/workflows/compress.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,20 @@ jobs:
2222
id: calibre
2323
uses: calibreapp/image-actions@main
2424
with:
25-
githubToken: ${{ secrets.GITHUB_TOKEN }}
25+
githubToken: ${{ secrets.ACTION_TOKEN }}
2626
compressOnly: true
2727

2828
- name: Commit Files
2929
if: |
3030
steps.calibre.outputs.markdown != ''
3131
run: |
32-
git config --local user.email "action@github.com"
33-
git config --local user.name "GitHub Action"
32+
git config --local user.email "szuyanglb@outlook.com"
33+
git config --local user.name "yanglbme"
3434
git commit -m "chore: auto compress images" -a
3535
3636
- name: Push Changes
3737
if: |
3838
steps.calibre.outputs.markdown != ''
3939
uses: ad-m/github-push-action@master
4040
with:
41-
github_token: ${{ secrets.GITHUB_TOKEN }}
41+
github_token: ${{ secrets.ACTION_TOKEN }}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# [2099. 找到和最大的长度为 K 的子序列](https://leetcode-cn.com/problems/find-subsequence-of-length-k-with-the-largest-sum)
2+
3+
[English Version](/solution/2000-2099/2099.Find%20Subsequence%20of%20Length%20K%20With%20the%20Largest%20Sum/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个整数数组&nbsp;<code>nums</code>&nbsp;和一个整数&nbsp;<code>k</code>&nbsp;。你需要找到&nbsp;<code>nums</code>&nbsp;中长度为 <code>k</code>&nbsp;的 <strong>子序列</strong>&nbsp;,且这个子序列的&nbsp;<strong>和最大&nbsp;</strong>。</p>
10+
11+
<p>请你返回 <strong>任意</strong> 一个长度为&nbsp;<code>k</code>&nbsp;的整数子序列。</p>
12+
13+
<p><strong>子序列</strong>&nbsp;定义为从一个数组里删除一些元素后,不改变剩下元素的顺序得到的数组。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong>示例 1:</strong></p>
18+
19+
<pre><b>输入:</b>nums = [2,1,3,3], k = 2
20+
<b>输出:</b>[3,3]
21+
<strong>解释:</strong>
22+
子序列有最大和:3 + 3 = 6 。</pre>
23+
24+
<p><strong>示例 2:</strong></p>
25+
26+
<pre><b>输入:</b>nums = [-1,-2,3,4], k = 3
27+
<b>输出:</b>[-1,3,4]
28+
<b>解释:</b>
29+
子序列有最大和:-1 + 3 + 4 = 6 。
30+
</pre>
31+
32+
<p><strong>示例 3:</strong></p>
33+
34+
<pre><b>输入:</b>nums = [3,4,3,3], k = 2
35+
<b>输出:</b>[3,4]
36+
<strong>解释:</strong>
37+
子序列有最大和:3 + 4 = 7 。
38+
另一个可行的子序列为 [4, 3] 。
39+
</pre>
40+
41+
<p>&nbsp;</p>
42+
43+
<p><strong>提示:</strong></p>
44+
45+
<ul>
46+
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
47+
<li><code>-10<sup>5</sup>&nbsp;&lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
48+
<li><code>1 &lt;= k &lt;= nums.length</code></li>
49+
</ul>
50+
51+
## 解法
52+
53+
<!-- 这里可写通用的实现逻辑 -->
54+
55+
<!-- tabs:start -->
56+
57+
### **Python3**
58+
59+
<!-- 这里可写当前语言的特殊实现逻辑 -->
60+
61+
```python
62+
63+
```
64+
65+
### **Java**
66+
67+
<!-- 这里可写当前语言的特殊实现逻辑 -->
68+
69+
```java
70+
71+
```
72+
73+
### **TypeScript**
74+
75+
<!-- 这里可写当前语言的特殊实现逻辑 -->
76+
77+
```ts
78+
79+
```
80+
81+
### **...**
82+
83+
```
84+
85+
```
86+
87+
<!-- tabs:end -->
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [2099. Find Subsequence of Length K With the Largest Sum](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum)
2+
3+
[中文文档](/solution/2000-2099/2099.Find%20Subsequence%20of%20Length%20K%20With%20the%20Largest%20Sum/README.md)
4+
5+
## Description
6+
7+
<p>You are given an integer array <code>nums</code> and an integer <code>k</code>. You want to find a <strong>subsequence </strong>of <code>nums</code> of length <code>k</code> that has the <strong>largest</strong> sum.</p>
8+
9+
<p>Return<em> </em><em><strong>any</strong> such subsequence as an integer array of length </em><code>k</code>.</p>
10+
11+
<p>A <strong>subsequence</strong> is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong>Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> nums = [2,1,3,3], k = 2
18+
<strong>Output:</strong> [3,3]
19+
<strong>Explanation:</strong>
20+
The subsequence has the largest sum of 3 + 3 = 6.</pre>
21+
22+
<p><strong>Example 2:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> nums = [-1,-2,3,4], k = 3
26+
<strong>Output:</strong> [-1,3,4]
27+
<strong>Explanation:</strong>
28+
The subsequence has the largest sum of -1 + 3 + 4 = 6.
29+
</pre>
30+
31+
<p><strong>Example 3:</strong></p>
32+
33+
<pre>
34+
<strong>Input:</strong> nums = [3,4,3,3], k = 2
35+
<strong>Output:</strong> [3,4]
36+
<strong>Explanation:</strong>
37+
The subsequence has the largest sum of 3 + 4 = 7.
38+
Another possible subsequence is [4, 3].
39+
</pre>
40+
41+
<p>&nbsp;</p>
42+
<p><strong>Constraints:</strong></p>
43+
44+
<ul>
45+
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
46+
<li><code>-10<sup>5</sup>&nbsp;&lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
47+
<li><code>1 &lt;= k &lt;= nums.length</code></li>
48+
</ul>
49+
50+
## Solutions
51+
52+
<!-- tabs:start -->
53+
54+
### **Python3**
55+
56+
```python
57+
58+
```
59+
60+
### **Java**
61+
62+
```java
63+
64+
```
65+
66+
### **TypeScript**
67+
68+
```ts
69+
70+
```
71+
72+
### **...**
73+
74+
```
75+
76+
```
77+
78+
<!-- tabs:end -->
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# [2100. 适合打劫银行的日子](https://leetcode-cn.com/problems/find-good-days-to-rob-the-bank)
2+
3+
[English Version](/solution/2100-2199/2100.Find%20Good%20Days%20to%20Rob%20the%20Bank/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>你和一群强盗准备打劫银行。给你一个下标从 <strong>0</strong>&nbsp;开始的整数数组&nbsp;<code>security</code>&nbsp;,其中&nbsp;<code>security[i]</code>&nbsp;是第 <code>i</code>&nbsp;天执勤警卫的数量。日子从 <code>0</code>&nbsp;开始编号。同时给你一个整数&nbsp;<code>time</code>&nbsp;。</p>
10+
11+
<p>如果第 <code>i</code>&nbsp;天满足以下所有条件,我们称它为一个适合打劫银行的日子:</p>
12+
13+
<ul>
14+
<li>第 <code>i</code>&nbsp;天前和后都分别至少有 <code>time</code>&nbsp;天。</li>
15+
<li>第 <code>i</code>&nbsp;天前连续 <code>time</code>&nbsp;天警卫数目都是非递增的。</li>
16+
<li>第 <code>i</code>&nbsp;天后连续 <code>time</code>&nbsp;天警卫数目都是非递减的。</li>
17+
</ul>
18+
19+
<p>更正式的,第 <code>i</code> 天是一个合适打劫银行的日子当且仅当:<code>security[i - time] &gt;= security[i - time + 1] &gt;= ... &gt;= security[i] &lt;= ... &lt;= security[i + time - 1] &lt;= security[i + time]</code>.</p>
20+
21+
<p>请你返回一个数组,包含 <strong>所有</strong> 适合打劫银行的日子(下标从 <strong>0</strong>&nbsp;开始)。返回的日子可以 <strong>任意</strong>&nbsp;顺序排列。</p>
22+
23+
<p>&nbsp;</p>
24+
25+
<p><strong>示例 1:</strong></p>
26+
27+
<pre>
28+
<strong>输入:</strong>security = [5,3,3,3,5,6,2], time = 2
29+
<b>输出:</b>[2,3]
30+
<strong>解释:</strong>
31+
第 2 天,我们有 security[0] &gt;= security[1] &gt;= security[2] &lt;= security[3] &lt;= security[4] 。
32+
第 3 天,我们有 security[1] &gt;= security[2] &gt;= security[3] &lt;= security[4] &lt;= security[5] 。
33+
没有其他日子符合这个条件,所以日子 2 和 3 是适合打劫银行的日子。
34+
</pre>
35+
36+
<p><strong>示例 2:</strong></p>
37+
38+
<pre>
39+
<b>输入:</b>security = [1,1,1,1,1], time = 0
40+
<b>输出:</b>[0,1,2,3,4]
41+
<strong>解释:</strong>
42+
因为 time 等于 0 ,所以每一天都是适合打劫银行的日子,所以返回每一天。
43+
</pre>
44+
45+
<p><strong>示例 3:</strong></p>
46+
47+
<pre>
48+
<b>输入:</b>security = [1,2,3,4,5,6], time = 2
49+
<b>输出:</b>[]
50+
<strong>解释:</strong>
51+
没有任何一天的前 2 天警卫数目是非递增的。
52+
所以没有适合打劫银行的日子,返回空数组。
53+
</pre>
54+
55+
<p><strong>示例 4:</strong></p>
56+
57+
<pre>
58+
<b>输入:</b>security = [1], time = 5
59+
<b>输出:</b>[]
60+
<strong>解释:</strong>
61+
没有日子前面和后面有 5 天时间。
62+
所以没有适合打劫银行的日子,返回空数组。</pre>
63+
64+
<p>&nbsp;</p>
65+
66+
<p><strong>提示:</strong></p>
67+
68+
<ul>
69+
<li><code>1 &lt;= security.length &lt;= 10<sup>5</sup></code></li>
70+
<li><code>0 &lt;= security[i], time &lt;= 10<sup>5</sup></code></li>
71+
</ul>
72+
73+
## 解法
74+
75+
<!-- 这里可写通用的实现逻辑 -->
76+
77+
<!-- tabs:start -->
78+
79+
### **Python3**
80+
81+
<!-- 这里可写当前语言的特殊实现逻辑 -->
82+
83+
```python
84+
85+
```
86+
87+
### **Java**
88+
89+
<!-- 这里可写当前语言的特殊实现逻辑 -->
90+
91+
```java
92+
93+
```
94+
95+
### **TypeScript**
96+
97+
<!-- 这里可写当前语言的特殊实现逻辑 -->
98+
99+
```ts
100+
101+
```
102+
103+
### **...**
104+
105+
```
106+
107+
```
108+
109+
<!-- tabs:end -->
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# [2100. Find Good Days to Rob the Bank](https://leetcode.com/problems/find-good-days-to-rob-the-bank)
2+
3+
[中文文档](/solution/2100-2199/2100.Find%20Good%20Days%20to%20Rob%20the%20Bank/README.md)
4+
5+
## Description
6+
7+
<p>You and a gang of thieves are planning on robbing a bank. You are given a <strong>0-indexed</strong> integer array <code>security</code>, where <code>security[i]</code> is the number of guards on duty on the <code>i<sup>th</sup></code> day. The days are numbered starting from <code>0</code>. You are also given an integer <code>time</code>.</p>
8+
9+
<p>The <code>i<sup>th</sup></code> day is a good day to rob the bank if:</p>
10+
11+
<ul>
12+
<li>There are at least <code>time</code> days before and after the <code>i<sup>th</sup></code> day,</li>
13+
<li>The number of guards at the bank for the <code>time</code> days <strong>before</strong> <code>i</code> are <strong>non-increasing</strong>, and</li>
14+
<li>The number of guards at the bank for the <code>time</code> days <strong>after</strong> <code>i</code> are <strong>non-decreasing</strong>.</li>
15+
</ul>
16+
17+
<p>More formally, this means day <code>i</code> is a good day to rob the bank if and only if <code>security[i - time] &gt;= security[i - time + 1] &gt;= ... &gt;= security[i] &lt;= ... &lt;= security[i + time - 1] &lt;= security[i + time]</code>.</p>
18+
19+
<p>Return <em>a list of <strong>all</strong> days <strong>(0-indexed) </strong>that are good days to rob the bank</em>.<em> The order that the days are returned in does<strong> </strong><strong>not</strong> matter.</em></p>
20+
21+
<p>&nbsp;</p>
22+
<p><strong>Example 1:</strong></p>
23+
24+
<pre>
25+
<strong>Input:</strong> security = [5,3,3,3,5,6,2], time = 2
26+
<strong>Output:</strong> [2,3]
27+
<strong>Explanation:</strong>
28+
On day 2, we have security[0] &gt;= security[1] &gt;= security[2] &lt;= security[3] &lt;= security[4].
29+
On day 3, we have security[1] &gt;= security[2] &gt;= security[3] &lt;= security[4] &lt;= security[5].
30+
No other days satisfy this condition, so days 2 and 3 are the only good days to rob the bank.
31+
</pre>
32+
33+
<p><strong>Example 2:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> security = [1,1,1,1,1], time = 0
37+
<strong>Output:</strong> [0,1,2,3,4]
38+
<strong>Explanation:</strong>
39+
Since time equals 0, every day is a good day to rob the bank, so return every day.
40+
</pre>
41+
42+
<p><strong>Example 3:</strong></p>
43+
44+
<pre>
45+
<strong>Input:</strong> security = [1,2,3,4,5,6], time = 2
46+
<strong>Output:</strong> []
47+
<strong>Explanation:</strong>
48+
No day has 2 days before it that have a non-increasing number of guards.
49+
Thus, no day is a good day to rob the bank, so return an empty list.
50+
</pre>
51+
52+
<p><strong>Example 4:</strong></p>
53+
54+
<pre>
55+
<strong>Input:</strong> security = [1], time = 5
56+
<strong>Output:</strong> []
57+
<strong>Explanation:</strong>
58+
No day has 5 days before and after it.
59+
Thus, no day is a good day to rob the bank, so return an empty list.</pre>
60+
61+
<p>&nbsp;</p>
62+
<p><strong>Constraints:</strong></p>
63+
64+
<ul>
65+
<li><code>1 &lt;= security.length &lt;= 10<sup>5</sup></code></li>
66+
<li><code>0 &lt;= security[i], time &lt;= 10<sup>5</sup></code></li>
67+
</ul>
68+
69+
## Solutions
70+
71+
<!-- tabs:start -->
72+
73+
### **Python3**
74+
75+
```python
76+
77+
```
78+
79+
### **Java**
80+
81+
```java
82+
83+
```
84+
85+
### **TypeScript**
86+
87+
```ts
88+
89+
```
90+
91+
### **...**
92+
93+
```
94+
95+
```
96+
97+
<!-- tabs:end -->

0 commit comments

Comments
 (0)