Skip to content

Commit f010fe0

Browse files
committed
feat: add solutions to lc problems
* No.2299.Strong Password Checker II * No.2300.Successful Pairs of Spells and Potions * No.2301.Match Substring After Replacement * No.2302.Count Subarrays With Score Less Than K * No.2303.Calculate Amount Paid in Taxes * No.2304.Minimum Path Cost in a Grid * No.2305.Fair Distribution of Cookies * No.2306.Naming a Company
1 parent fedaa29 commit f010fe0

File tree

53 files changed

+3707
-14
lines changed

Some content is hidden

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

53 files changed

+3707
-14
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# [2297. Jump Game IX](https://leetcode.cn/problems/jump-game-ix)
2+
3+
[English Version](/solution/2200-2299/2297.Jump%20Game%20IX/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>. You are initially standing at index <code>0</code>. You can jump from index <code>i</code> to index <code>j</code> where <code>i &lt; j</code> if:</p>
10+
11+
<ul>
12+
<li><code>nums[i] &lt;= nums[j]</code> and <code>nums[k] &lt; nums[i]</code> for all indexes <code>k</code> in the range <code>i &lt; k &lt; j</code>, or</li>
13+
<li><code>nums[i] &gt; nums[j]</code> and <code>nums[k] &gt;= nums[i]</code> for all indexes <code>k</code> in the range <code>i &lt; k &lt; j</code>.</li>
14+
</ul>
15+
16+
<p>You are also given an integer array <code>costs</code> of length <code>n</code> where <code>costs[i]</code> denotes the cost of jumping <strong>to</strong> index <code>i</code>.</p>
17+
18+
<p>Return <em>the <strong>minimum</strong> cost to jump to the index </em><code>n - 1</code>.</p>
19+
20+
<p>&nbsp;</p>
21+
<p><strong>Example 1:</strong></p>
22+
23+
<pre>
24+
<strong>Input:</strong> nums = [3,2,4,4,1], costs = [3,7,6,4,2]
25+
<strong>Output:</strong> 8
26+
<strong>Explanation:</strong> You start at index 0.
27+
- Jump to index 2 with a cost of costs[2] = 6.
28+
- Jump to index 4 with a cost of costs[4] = 2.
29+
The total cost is 8. It can be proven that 8 is the minimum cost needed.
30+
Two other possible paths are from index 0 -&gt; 1 -&gt; 4 and index 0 -&gt; 2 -&gt; 3 -&gt; 4.
31+
These have a total cost of 9 and 12, respectively.
32+
</pre>
33+
34+
<p><strong>Example 2:</strong></p>
35+
36+
<pre>
37+
<strong>Input:</strong> nums = [0,1,2], costs = [1,1,1]
38+
<strong>Output:</strong> 2
39+
<strong>Explanation:</strong> Start at index 0.
40+
- Jump to index 1 with a cost of costs[1] = 1.
41+
- Jump to index 2 with a cost of costs[2] = 1.
42+
The total cost is 2. Note that you cannot jump directly from index 0 to index 2 because nums[0] &lt;= nums[1].
43+
</pre>
44+
45+
<p>&nbsp;</p>
46+
<p><strong>Constraints:</strong></p>
47+
48+
<ul>
49+
<li><code>n == nums.length == costs.length</code></li>
50+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
51+
<li><code>0 &lt;= nums[i], costs[i] &lt;= 10<sup>5</sup></code></li>
52+
</ul>
53+
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+
### **TypeScript**
78+
79+
```ts
80+
81+
```
82+
83+
### **...**
84+
85+
```
86+
87+
```
88+
89+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# [2297. Jump Game IX](https://leetcode.com/problems/jump-game-ix)
2+
3+
[中文文档](/solution/2200-2299/2297.Jump%20Game%20IX/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of length <code>n</code>. You are initially standing at index <code>0</code>. You can jump from index <code>i</code> to index <code>j</code> where <code>i &lt; j</code> if:</p>
8+
9+
<ul>
10+
<li><code>nums[i] &lt;= nums[j]</code> and <code>nums[k] &lt; nums[i]</code> for all indexes <code>k</code> in the range <code>i &lt; k &lt; j</code>, or</li>
11+
<li><code>nums[i] &gt; nums[j]</code> and <code>nums[k] &gt;= nums[i]</code> for all indexes <code>k</code> in the range <code>i &lt; k &lt; j</code>.</li>
12+
</ul>
13+
14+
<p>You are also given an integer array <code>costs</code> of length <code>n</code> where <code>costs[i]</code> denotes the cost of jumping <strong>to</strong> index <code>i</code>.</p>
15+
16+
<p>Return <em>the <strong>minimum</strong> cost to jump to the index </em><code>n - 1</code>.</p>
17+
18+
<p>&nbsp;</p>
19+
<p><strong>Example 1:</strong></p>
20+
21+
<pre>
22+
<strong>Input:</strong> nums = [3,2,4,4,1], costs = [3,7,6,4,2]
23+
<strong>Output:</strong> 8
24+
<strong>Explanation:</strong> You start at index 0.
25+
- Jump to index 2 with a cost of costs[2] = 6.
26+
- Jump to index 4 with a cost of costs[4] = 2.
27+
The total cost is 8. It can be proven that 8 is the minimum cost needed.
28+
Two other possible paths are from index 0 -&gt; 1 -&gt; 4 and index 0 -&gt; 2 -&gt; 3 -&gt; 4.
29+
These have a total cost of 9 and 12, respectively.
30+
</pre>
31+
32+
<p><strong>Example 2:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong> nums = [0,1,2], costs = [1,1,1]
36+
<strong>Output:</strong> 2
37+
<strong>Explanation:</strong> Start at index 0.
38+
- Jump to index 1 with a cost of costs[1] = 1.
39+
- Jump to index 2 with a cost of costs[2] = 1.
40+
The total cost is 2. Note that you cannot jump directly from index 0 to index 2 because nums[0] &lt;= nums[1].
41+
</pre>
42+
43+
<p>&nbsp;</p>
44+
<p><strong>Constraints:</strong></p>
45+
46+
<ul>
47+
<li><code>n == nums.length == costs.length</code></li>
48+
<li><code>1 &lt;= n &lt;= 10<sup>5</sup></code></li>
49+
<li><code>0 &lt;= nums[i], costs[i] &lt;= 10<sup>5</sup></code></li>
50+
</ul>
51+
52+
53+
## Solutions
54+
55+
<!-- tabs:start -->
56+
57+
### **Python3**
58+
59+
```python
60+
61+
```
62+
63+
### **Java**
64+
65+
```java
66+
67+
```
68+
69+
### **TypeScript**
70+
71+
```ts
72+
73+
```
74+
75+
### **...**
76+
77+
```
78+
79+
```
80+
81+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# [2298. Tasks Count in the Weekend](https://leetcode.cn/problems/tasks-count-in-the-weekend)
2+
3+
[English Version](/solution/2200-2299/2298.Tasks%20Count%20in%20the%20Weekend/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code>Tasks</code></p>
10+
11+
<pre>
12+
+-------------+------+
13+
| Column Name | Type |
14+
+-------------+------+
15+
| task_id | int |
16+
| assignee_id | int |
17+
| submit_date | date |
18+
+-------------+------+
19+
task_id is the primary key for this table.
20+
Each row in this table contains the ID of a task, the id of the assignee, and the submission date.
21+
</pre>
22+
23+
<p>&nbsp;</p>
24+
25+
<p>Write an SQL query to report:</p>
26+
27+
<ul>
28+
<li>the number of the tasks that were submitted during the weekend (Saturday, Sunday) as <code>weekend_cnt</code>, and</li>
29+
<li>the number of the tasks that were submitted during the working days as <code>working_cnt</code>.</li>
30+
</ul>
31+
32+
<p>Return the result table in <strong>any order</strong>.</p>
33+
34+
<p>The query result format is shown in the following example.</p>
35+
36+
<p>&nbsp;</p>
37+
<p><strong>Example 1:</strong></p>
38+
39+
<pre>
40+
<strong>Input:</strong>
41+
Tasks table:
42+
+---------+-------------+-------------+
43+
| task_id | assignee_id | submit_date |
44+
+---------+-------------+-------------+
45+
| 1 | 1 | 2022-06-13 |
46+
| 2 | 6 | 2022-06-14 |
47+
| 3 | 6 | 2022-06-15 |
48+
| 4 | 3 | 2022-06-18 |
49+
| 5 | 5 | 2022-06-19 |
50+
| 6 | 7 | 2022-06-19 |
51+
+---------+-------------+-------------+
52+
<strong>Output:</strong>
53+
+-------------+-------------+
54+
| weekend_cnt | working_cnt |
55+
+-------------+-------------+
56+
| 3 | 3 |
57+
+-------------+-------------+
58+
<strong>Explanation:</strong>
59+
Task 1 was submitted on Monday.
60+
Task 2 was submitted on Tuesday.
61+
Task 3 was submitted on Wednesday.
62+
Task 4 was submitted on Saturday.
63+
Task 5 was submitted on Sunday.
64+
Task 6 was submitted on Sunday.
65+
3 tasks were submitted during the weekends.
66+
3 tasks were submitted during the working days.
67+
</pre>
68+
69+
70+
## 解法
71+
72+
<!-- 这里可写通用的实现逻辑 -->
73+
74+
<!-- tabs:start -->
75+
76+
### **Python3**
77+
78+
<!-- 这里可写当前语言的特殊实现逻辑 -->
79+
80+
```python
81+
82+
```
83+
84+
### **Java**
85+
86+
<!-- 这里可写当前语言的特殊实现逻辑 -->
87+
88+
```java
89+
90+
```
91+
92+
### **TypeScript**
93+
94+
```ts
95+
96+
```
97+
98+
### **...**
99+
100+
```
101+
102+
```
103+
104+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# [2298. Tasks Count in the Weekend](https://leetcode.com/problems/tasks-count-in-the-weekend)
2+
3+
[中文文档](/solution/2200-2299/2298.Tasks%20Count%20in%20the%20Weekend/README.md)
4+
5+
## Description
6+
7+
<p>Table: <code>Tasks</code></p>
8+
9+
<pre>
10+
+-------------+------+
11+
| Column Name | Type |
12+
+-------------+------+
13+
| task_id | int |
14+
| assignee_id | int |
15+
| submit_date | date |
16+
+-------------+------+
17+
task_id is the primary key for this table.
18+
Each row in this table contains the ID of a task, the id of the assignee, and the submission date.
19+
</pre>
20+
21+
<p>&nbsp;</p>
22+
23+
<p>Write an SQL query to report:</p>
24+
25+
<ul>
26+
<li>the number of the tasks that were submitted during the weekend (Saturday, Sunday) as <code>weekend_cnt</code>, and</li>
27+
<li>the number of the tasks that were submitted during the working days as <code>working_cnt</code>.</li>
28+
</ul>
29+
30+
<p>Return the result table in <strong>any order</strong>.</p>
31+
32+
<p>The query result format is shown in the following example.</p>
33+
34+
<p>&nbsp;</p>
35+
<p><strong>Example 1:</strong></p>
36+
37+
<pre>
38+
<strong>Input:</strong>
39+
Tasks table:
40+
+---------+-------------+-------------+
41+
| task_id | assignee_id | submit_date |
42+
+---------+-------------+-------------+
43+
| 1 | 1 | 2022-06-13 |
44+
| 2 | 6 | 2022-06-14 |
45+
| 3 | 6 | 2022-06-15 |
46+
| 4 | 3 | 2022-06-18 |
47+
| 5 | 5 | 2022-06-19 |
48+
| 6 | 7 | 2022-06-19 |
49+
+---------+-------------+-------------+
50+
<strong>Output:</strong>
51+
+-------------+-------------+
52+
| weekend_cnt | working_cnt |
53+
+-------------+-------------+
54+
| 3 | 3 |
55+
+-------------+-------------+
56+
<strong>Explanation:</strong>
57+
Task 1 was submitted on Monday.
58+
Task 2 was submitted on Tuesday.
59+
Task 3 was submitted on Wednesday.
60+
Task 4 was submitted on Saturday.
61+
Task 5 was submitted on Sunday.
62+
Task 6 was submitted on Sunday.
63+
3 tasks were submitted during the weekends.
64+
3 tasks were submitted during the working days.
65+
</pre>
66+
67+
68+
## Solutions
69+
70+
<!-- tabs:start -->
71+
72+
### **Python3**
73+
74+
```python
75+
76+
```
77+
78+
### **Java**
79+
80+
```java
81+
82+
```
83+
84+
### **TypeScript**
85+
86+
```ts
87+
88+
```
89+
90+
### **...**
91+
92+
```
93+
94+
```
95+
96+
<!-- tabs:end -->

0 commit comments

Comments
 (0)