Skip to content

Commit 0d7a8d4

Browse files
committed
feat: add new lc problems
1 parent b656625 commit 0d7a8d4

File tree

22 files changed

+846
-22
lines changed

22 files changed

+846
-22
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [2247. Maximum Cost of Trip With K Highways](https://leetcode-cn.com/problems/maximum-cost-of-trip-with-k-highways)
2+
3+
[English Version](/solution/2200-2299/2247.Maximum%20Cost%20of%20Trip%20With%20K%20Highways/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>A series of highways connect <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. You are given a 2D integer array <code>highways</code> where <code>highways[i] = [city1<sub>i</sub>, city2<sub>i</sub>, toll<sub>i</sub>]</code> indicates that there is a highway that connects <code>city1<sub>i</sub></code> and <code>city2<sub>i</sub></code>, allowing a car to go from <code>city1<sub>i</sub></code> to <code>city2<sub>i</sub></code> and <strong>vice versa</strong> for a cost of <code>toll<sub>i</sub></code>.</p>
10+
11+
<p>You are also given an integer <code>k</code>. You are going on a trip that crosses <strong>exactly</strong> <code>k</code> highways. You may start at any city, but you may only visit each city <strong>at most</strong> once during your trip.</p>
12+
13+
<p>Return<em> the <strong>maximum</strong> cost of your trip. If there is no trip that meets the requirements, return </em><code>-1</code><em>.</em></p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong>Example 1:</strong></p>
17+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2247.Maximum%20Cost%20of%20Trip%20With%20K%20Highways/images/image-20220418173304-1.png" style="height: 200px; width: 327px;" />
18+
<pre>
19+
<strong>Input:</strong> n = 5, highways = [[0,1,4],[2,1,3],[1,4,11],[3,2,3],[3,4,2]], k = 3
20+
<strong>Output:</strong> 17
21+
<strong>Explanation:</strong>
22+
One possible trip is to go from 0 -&gt; 1 -&gt; 4 -&gt; 3. The cost of this trip is 4 + 11 + 2 = 17.
23+
Another possible trip is to go from 4 -&gt; 1 -&gt; 2 -&gt; 3. The cost of this trip is 11 + 3 + 3 = 17.
24+
It can be proven that 17 is the maximum possible cost of any valid trip.
25+
26+
Note that the trip 4 -&gt; 1 -&gt; 0 -&gt; 1 is not allowed because you visit the city 1 twice.
27+
</pre>
28+
29+
<p><strong>Example 2:</strong></p>
30+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2247.Maximum%20Cost%20of%20Trip%20With%20K%20Highways/images/image-20220418173342-2.png" style="height: 200px; width: 217px;" />
31+
<pre>
32+
<strong>Input:</strong> n = 4, highways = [[0,1,3],[2,3,2]], k = 2
33+
<strong>Output:</strong> -1
34+
<strong>Explanation:</strong> There are no valid trips of length 2, so return -1.
35+
</pre>
36+
37+
<p>&nbsp;</p>
38+
<p><strong>Constraints:</strong></p>
39+
40+
<ul>
41+
<li><code>2 &lt;= n &lt;= 15</code></li>
42+
<li><code>1 &lt;= highways.length &lt;= 50</code></li>
43+
<li><code>highways[i].length == 3</code></li>
44+
<li><code>0 &lt;= city1<sub>i</sub>, city2<sub>i</sub> &lt;= n - 1</code></li>
45+
<li><code>city1<sub>i</sub> != city2<sub>i</sub></code></li>
46+
<li><code>0 &lt;= toll<sub>i</sub> &lt;= 100</code></li>
47+
<li><code>1 &lt;= k &lt;= 50</code></li>
48+
<li>There are no duplicate highways.</li>
49+
</ul>
50+
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+
### **TypeScript**
75+
76+
```ts
77+
78+
```
79+
80+
### **...**
81+
82+
```
83+
84+
```
85+
86+
<!-- tabs:end -->
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# [2247. Maximum Cost of Trip With K Highways](https://leetcode.com/problems/maximum-cost-of-trip-with-k-highways)
2+
3+
[中文文档](/solution/2200-2299/2247.Maximum%20Cost%20of%20Trip%20With%20K%20Highways/README.md)
4+
5+
## Description
6+
7+
<p>A series of highways connect <code>n</code> cities numbered from <code>0</code> to <code>n - 1</code>. You are given a 2D integer array <code>highways</code> where <code>highways[i] = [city1<sub>i</sub>, city2<sub>i</sub>, toll<sub>i</sub>]</code> indicates that there is a highway that connects <code>city1<sub>i</sub></code> and <code>city2<sub>i</sub></code>, allowing a car to go from <code>city1<sub>i</sub></code> to <code>city2<sub>i</sub></code> and <strong>vice versa</strong> for a cost of <code>toll<sub>i</sub></code>.</p>
8+
9+
<p>You are also given an integer <code>k</code>. You are going on a trip that crosses <strong>exactly</strong> <code>k</code> highways. You may start at any city, but you may only visit each city <strong>at most</strong> once during your trip.</p>
10+
11+
<p>Return<em> the <strong>maximum</strong> cost of your trip. If there is no trip that meets the requirements, return </em><code>-1</code><em>.</em></p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong>Example 1:</strong></p>
15+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2247.Maximum%20Cost%20of%20Trip%20With%20K%20Highways/images/image-20220418173304-1.png" style="height: 200px; width: 327px;" />
16+
<pre>
17+
<strong>Input:</strong> n = 5, highways = [[0,1,4],[2,1,3],[1,4,11],[3,2,3],[3,4,2]], k = 3
18+
<strong>Output:</strong> 17
19+
<strong>Explanation:</strong>
20+
One possible trip is to go from 0 -&gt; 1 -&gt; 4 -&gt; 3. The cost of this trip is 4 + 11 + 2 = 17.
21+
Another possible trip is to go from 4 -&gt; 1 -&gt; 2 -&gt; 3. The cost of this trip is 11 + 3 + 3 = 17.
22+
It can be proven that 17 is the maximum possible cost of any valid trip.
23+
24+
Note that the trip 4 -&gt; 1 -&gt; 0 -&gt; 1 is not allowed because you visit the city 1 twice.
25+
</pre>
26+
27+
<p><strong>Example 2:</strong></p>
28+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2247.Maximum%20Cost%20of%20Trip%20With%20K%20Highways/images/image-20220418173342-2.png" style="height: 200px; width: 217px;" />
29+
<pre>
30+
<strong>Input:</strong> n = 4, highways = [[0,1,3],[2,3,2]], k = 2
31+
<strong>Output:</strong> -1
32+
<strong>Explanation:</strong> There are no valid trips of length 2, so return -1.
33+
</pre>
34+
35+
<p>&nbsp;</p>
36+
<p><strong>Constraints:</strong></p>
37+
38+
<ul>
39+
<li><code>2 &lt;= n &lt;= 15</code></li>
40+
<li><code>1 &lt;= highways.length &lt;= 50</code></li>
41+
<li><code>highways[i].length == 3</code></li>
42+
<li><code>0 &lt;= city1<sub>i</sub>, city2<sub>i</sub> &lt;= n - 1</code></li>
43+
<li><code>city1<sub>i</sub> != city2<sub>i</sub></code></li>
44+
<li><code>0 &lt;= toll<sub>i</sub> &lt;= 100</code></li>
45+
<li><code>1 &lt;= k &lt;= 50</code></li>
46+
<li>There are no duplicate highways.</li>
47+
</ul>
48+
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: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# [2248. 多个数组求交集](https://leetcode-cn.com/problems/intersection-of-multiple-arrays)
2+
3+
[English Version](/solution/2200-2299/2248.Intersection%20of%20Multiple%20Arrays/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个二维整数数组 <code>nums</code> ,其中 <code>nums[i]</code> 是由 <strong>不同</strong> 正整数组成的一个非空数组,按 <strong>升序排列</strong> 返回一个数组,数组中的每个元素在 <code>nums</code>&nbsp;<strong>所有数组</strong> 中都出现过。</p>
10+
11+
<p>&nbsp;</p>
12+
13+
<p><strong>示例 1:</strong></p>
14+
15+
<pre>
16+
<strong>输入:</strong>nums = [[<em><strong>3</strong></em>,1,2,<em><strong>4</strong></em>,5],[1,2,<em><strong>3</strong></em>,<em><strong>4</strong></em>],[<em><strong>3</strong></em>,<em><strong>4</strong></em>,5,6]]
17+
<strong>输出:</strong>[3,4]
18+
<strong>解释:</strong>
19+
nums[0] = [<em><strong>3</strong></em>,1,2,<em><strong>4</strong></em>,5],nums[1] = [1,2,<em><strong>3</strong></em>,<em><strong>4</strong></em>],nums[2] = [<em><strong>3</strong></em>,<em><strong>4</strong></em>,5,6],在 nums 中每个数组中都出现的数字是 3 和 4 ,所以返回 [3,4] 。</pre>
20+
21+
<p><strong>示例 2:</strong></p>
22+
23+
<pre>
24+
<strong>输入:</strong>nums = [[1,2,3],[4,5,6]]
25+
<strong>输出:</strong>[]
26+
<strong>解释:</strong>
27+
不存在同时出现在 nums[0] 和 nums[1] 的整数,所以返回一个空列表 [] 。
28+
</pre>
29+
30+
<p>&nbsp;</p>
31+
32+
<p><strong>提示:</strong></p>
33+
34+
<ul>
35+
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
36+
<li><code>1 &lt;= sum(nums[i].length) &lt;= 1000</code></li>
37+
<li><code>1 &lt;= nums[i][j] &lt;= 1000</code></li>
38+
<li><code>nums[i]</code> 中的所有值 <strong>互不相同</strong></li>
39+
</ul>
40+
41+
## 解法
42+
43+
<!-- 这里可写通用的实现逻辑 -->
44+
45+
<!-- tabs:start -->
46+
47+
### **Python3**
48+
49+
<!-- 这里可写当前语言的特殊实现逻辑 -->
50+
51+
```python
52+
53+
```
54+
55+
### **Java**
56+
57+
<!-- 这里可写当前语言的特殊实现逻辑 -->
58+
59+
```java
60+
61+
```
62+
63+
### **TypeScript**
64+
65+
```ts
66+
67+
```
68+
69+
### **...**
70+
71+
```
72+
73+
```
74+
75+
<!-- tabs:end -->
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# [2248. Intersection of Multiple Arrays](https://leetcode.com/problems/intersection-of-multiple-arrays)
2+
3+
[中文文档](/solution/2200-2299/2248.Intersection%20of%20Multiple%20Arrays/README.md)
4+
5+
## Description
6+
7+
Given a 2D integer array <code>nums</code> where <code>nums[i]</code> is a non-empty array of <strong>distinct</strong> positive integers, return <em>the list of integers that are present in <strong>each array</strong> of</em> <code>nums</code><em> sorted in <strong>ascending order</strong></em>.
8+
9+
<p>&nbsp;</p>
10+
<p><strong>Example 1:</strong></p>
11+
12+
<pre>
13+
<strong>Input:</strong> nums = [[<u><strong>3</strong></u>,1,2,<u><strong>4</strong></u>,5],[1,2,<u><strong>3</strong></u>,<u><strong>4</strong></u>],[<u><strong>3</strong></u>,<u><strong>4</strong></u>,5,6]]
14+
<strong>Output:</strong> [3,4]
15+
<strong>Explanation:</strong>
16+
The only integers present in each of nums[0] = [<u><strong>3</strong></u>,1,2,<u><strong>4</strong></u>,5], nums[1] = [1,2,<u><strong>3</strong></u>,<u><strong>4</strong></u>], and nums[2] = [<u><strong>3</strong></u>,<u><strong>4</strong></u>,5,6] are 3 and 4, so we return [3,4].</pre>
17+
18+
<p><strong>Example 2:</strong></p>
19+
20+
<pre>
21+
<strong>Input:</strong> nums = [[1,2,3],[4,5,6]]
22+
<strong>Output:</strong> []
23+
<strong>Explanation:</strong>
24+
There does not exist any integer present both in nums[0] and nums[1], so we return an empty list [].
25+
</pre>
26+
27+
<p>&nbsp;</p>
28+
<p><strong>Constraints:</strong></p>
29+
30+
<ul>
31+
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
32+
<li><code>1 &lt;= sum(nums[i].length) &lt;= 1000</code></li>
33+
<li><code>1 &lt;= nums[i][j] &lt;= 1000</code></li>
34+
<li>All the values of <code>nums[i]</code> are <strong>unique</strong>.</li>
35+
</ul>
36+
37+
## Solutions
38+
39+
<!-- tabs:start -->
40+
41+
### **Python3**
42+
43+
```python
44+
45+
```
46+
47+
### **Java**
48+
49+
```java
50+
51+
```
52+
53+
### **TypeScript**
54+
55+
```ts
56+
57+
```
58+
59+
### **...**
60+
61+
```
62+
63+
```
64+
65+
<!-- tabs:end -->
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# [2249. 统计圆内格点数目](https://leetcode-cn.com/problems/count-lattice-points-inside-a-circle)
2+
3+
[English Version](/solution/2200-2299/2249.Count%20Lattice%20Points%20Inside%20a%20Circle/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个二维整数数组 <code>circles</code> ,其中 <code>circles[i] = [x<sub>i</sub>, y<sub>i</sub>, r<sub>i</sub>]</code> 表示网格上圆心为 <code>(x<sub>i</sub>, y<sub>i</sub>)</code> 且半径为 <code>r<sub>i</sub></code> 的第 <code>i</code> 个圆,返回出现在<strong> 至少一个 </strong>圆内的 <strong>格点数目</strong> 。</p>
10+
11+
<p><strong>注意:</strong></p>
12+
13+
<ul>
14+
<li><strong>格点</strong> 是指整数坐标对应的点。</li>
15+
<li><strong>圆周上的点</strong> 也被视为出现在圆内的点。</li>
16+
</ul>
17+
18+
<p>&nbsp;</p>
19+
20+
<p><strong>示例 1:</strong></p>
21+
22+
<p><img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2249.Count%20Lattice%20Points%20Inside%20a%20Circle/images/exa-11.png" style="width: 300px; height: 300px;" /></p>
23+
24+
<pre>
25+
<strong>输入:</strong>circles = [[2,2,1]]
26+
<strong>输出:</strong>5
27+
<strong>解释:</strong>
28+
给定的圆如上图所示。
29+
出现在圆内的格点为 (1, 2)、(2, 1)、(2, 2)、(2, 3) 和 (3, 2),在图中用绿色标识。
30+
像 (1, 1) 和 (1, 3) 这样用红色标识的点,并未出现在圆内。
31+
因此,出现在至少一个圆内的格点数目是 5 。</pre>
32+
33+
<p><strong>示例 2:</strong></p>
34+
35+
<p><img alt="" src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2200-2299/2249.Count%20Lattice%20Points%20Inside%20a%20Circle/images/exa-22.png" style="width: 300px; height: 300px;" /></p>
36+
37+
<pre>
38+
<strong>输入:</strong>circles = [[2,2,2],[3,4,1]]
39+
<strong>输出:</strong>16
40+
<strong>解释:</strong>
41+
给定的圆如上图所示。
42+
共有 16 个格点出现在至少一个圆内。
43+
其中部分点的坐标是 (0, 2)、(2, 0)、(2, 4)、(3, 2) 和 (4, 4) 。
44+
</pre>
45+
46+
<p>&nbsp;</p>
47+
48+
<p><strong>提示:</strong></p>
49+
50+
<ul>
51+
<li><code>1 &lt;= circles.length &lt;= 200</code></li>
52+
<li><code>circles[i].length == 3</code></li>
53+
<li><code>1 &lt;= x<sub>i</sub>, y<sub>i</sub> &lt;= 100</code></li>
54+
<li><code>1 &lt;= r<sub>i</sub> &lt;= min(x<sub>i</sub>, y<sub>i</sub>)</code></li>
55+
</ul>
56+
57+
## 解法
58+
59+
<!-- 这里可写通用的实现逻辑 -->
60+
61+
<!-- tabs:start -->
62+
63+
### **Python3**
64+
65+
<!-- 这里可写当前语言的特殊实现逻辑 -->
66+
67+
```python
68+
69+
```
70+
71+
### **Java**
72+
73+
<!-- 这里可写当前语言的特殊实现逻辑 -->
74+
75+
```java
76+
77+
```
78+
79+
### **TypeScript**
80+
81+
```ts
82+
83+
```
84+
85+
### **...**
86+
87+
```
88+
89+
```
90+
91+
<!-- tabs:end -->

0 commit comments

Comments
 (0)