Skip to content

Commit 1f42ee8

Browse files
committed
feat: add new lc problems
1 parent 15dd23d commit 1f42ee8

34 files changed

+2265
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
---
2+
comments: true
3+
difficulty: 中等
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3540.Minimum%20Time%20to%20Visit%20All%20Houses/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3540. 访问所有房屋的最短时间 🔒](https://leetcode.cn/problems/minimum-time-to-visit-all-houses)
10+
11+
[English Version](/solution/3500-3599/3540.Minimum%20Time%20to%20Visit%20All%20Houses/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给定两个整数数组&nbsp;<code>forward</code> 和&nbsp;<code>backward</code>,长度都为&nbsp;<code>n</code>。同时给定另一个整数数组&nbsp;<code>queries</code>。</p>
18+
19+
<p>有&nbsp;<code>n</code>&nbsp;个排列为环形的房屋。房屋通过道路以特殊方式相连:</p>
20+
21+
<ul>
22+
<li>对于所有的&nbsp;<code>0 &lt;= i &lt;= n - 2</code>,房屋&nbsp;<code>i</code>&nbsp;通过一条长度为&nbsp;<code>forward[i]</code>&nbsp;米的道路连接到房屋&nbsp;<code>i + 1</code>。另外,房屋&nbsp;<code>n - 1</code>&nbsp;通过一条长度为&nbsp;<code>forward[n - 1]</code>&nbsp;米的道路连接回房屋 0,形成一个环。</li>
23+
<li>对于所有的 <code>1 &lt;= i &lt;= n - 1</code>,房屋&nbsp;<code>i</code>&nbsp;通过一条长度为&nbsp;<code>backward[i]</code>&nbsp;米的道路连接到房屋&nbsp;<code>i - 1</code>。另外,房屋&nbsp;0 通过一条长度为&nbsp;<code>backward[n - 1]</code>&nbsp;米的道路连接回房屋&nbsp;<code>n - 1</code>,形成一个环。</li>
24+
</ul>
25+
26+
<p>你可以以 <strong>1</strong> 米每秒的速度行走。从房屋&nbsp;0 开始,找到按照&nbsp;<code>queries</code>&nbsp;指定的顺序访问每所房屋的 <strong>最小</strong> 时间。</p>
27+
28+
<p>返回访问房屋所需的 <strong>最短</strong> 总时间。</p>
29+
30+
<p>&nbsp;</p>
31+
32+
<p><strong class="example">示例 1:</strong></p>
33+
34+
<div class="example-block">
35+
<p><span class="example-io"><b>输入:</b>forward = [1,4,4], backward = [4,1,2], queries = [1,2,0,2]</span></p>
36+
37+
<p><b>输出:</b>12</p>
38+
39+
<p><b>解释:</b></p>
40+
41+
<p>路径如下:<code><u>0</u><sup>(0)</sup> → <u>1</u><sup>(1)</sup> → <u>2</u><sup>(5)</sup> <u>→</u> 1<sup>(7)</sup> <u>→</u> <u>0</u><sup>(8)</sup> <u>→</u> <u>2</u><sup>(12)</sup></code>。</p>
42+
43+
<p><strong>注意:</strong>使用的&nbsp;<code>node<sup>(total time)</sup></code>&nbsp;符号,<code>→</code>&nbsp;表示前向道路,<code><u>→</u></code>&nbsp;表示反向道路。</p>
44+
</div>
45+
46+
<p><strong class="example">示例 2:</strong></p>
47+
48+
<div class="example-block">
49+
<p><strong>输入:</strong><span class="example-io">forward = [1,1,1,1], backward = [2,2,2,2], queries = [1,2,3,0]</span></p>
50+
51+
<p><span class="example-io"><b>输出:</b>4</span></p>
52+
53+
<p><strong>解释:</strong></p>
54+
55+
<p>经过路径是&nbsp;<code><u>0</u> → <u>1</u> → <u>2</u> →​​​​​​​ <u>3</u> → <u>0</u></code>。每一步都在前向方向,需要 1 秒。</p>
56+
</div>
57+
58+
<p>&nbsp;</p>
59+
60+
<p><strong>提示:</strong></p>
61+
62+
<ul>
63+
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
64+
<li><code>n == forward.length == backward.length</code></li>
65+
<li><code>1 &lt;= forward[i], backward[i] &lt;= 10<sup>5</sup></code></li>
66+
<li><code>1 &lt;= queries.length &lt;= 10<sup>5</sup></code></li>
67+
<li><code>0 &lt;= queries[i] &lt; n</code></li>
68+
<li><code>queries[i] != queries[i + 1]</code></li>
69+
<li><code>queries[0]</code>&nbsp;非 0。</li>
70+
</ul>
71+
72+
<!-- description:end -->
73+
74+
## 解法
75+
76+
<!-- solution:start -->
77+
78+
### 方法一
79+
80+
<!-- tabs:start -->
81+
82+
#### Python3
83+
84+
```python
85+
86+
```
87+
88+
#### Java
89+
90+
```java
91+
92+
```
93+
94+
#### C++
95+
96+
```cpp
97+
98+
```
99+
100+
#### Go
101+
102+
```go
103+
104+
```
105+
106+
<!-- tabs:end -->
107+
108+
<!-- solution:end -->
109+
110+
<!-- problem:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
comments: true
3+
difficulty: Medium
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3540.Minimum%20Time%20to%20Visit%20All%20Houses/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3540. Minimum Time to Visit All Houses 🔒](https://leetcode.com/problems/minimum-time-to-visit-all-houses)
10+
11+
[中文文档](/solution/3500-3599/3540.Minimum%20Time%20to%20Visit%20All%20Houses/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p>You are given two integer arrays <code>forward</code> and <code>backward</code>, both of size <code>n</code>. You are also given another integer array <code>queries</code>.</p>
18+
19+
<p>There are <code>n</code> houses <em>arranged in a circle</em>. The houses are connected via roads in a special arrangement:</p>
20+
21+
<ul>
22+
<li>For all <code>0 &lt;= i &lt;= n - 2</code>, house <code>i</code> is connected to house <code>i + 1</code> via a road with length <code>forward[i]</code> meters. Additionally, house <code>n - 1</code> is connected back to house 0 via a road with length <code>forward[n - 1]</code> meters, completing the circle.</li>
23+
<li>For all <code>1 &lt;= i &lt;= n - 1</code>, house <code>i</code> is connected to house <code>i - 1</code> via a road with length <code>backward[i]</code> meters. Additionally, house 0 is connected back to house <code>n - 1</code> via a road with length <code>backward[0]</code> meters, completing the circle.</li>
24+
</ul>
25+
26+
<p>You can walk at a pace of <strong>one</strong> meter per second. Starting from house 0, find the <strong>minimum</strong> time taken to visit each house in the order specified by <code>queries</code>.</p>
27+
28+
<p>Return the <strong>minimum</strong> total time taken to visit the houses.</p>
29+
30+
<p>&nbsp;</p>
31+
<p><strong class="example">Example 1:</strong></p>
32+
33+
<div class="example-block">
34+
<p><strong>Input:</strong> <span class="example-io">forward = [1,4,4], backward = [4,1,2], queries = [1,2,0,2]</span></p>
35+
36+
<p><strong>Output:</strong> 12</p>
37+
38+
<p><strong>Explanation:</strong></p>
39+
40+
<p>The path followed is <code><u>0</u><sup>(0)</sup> &rarr; <u>1</u><sup>(1)</sup> &rarr;​​​​​​​ <u>2</u><sup>(5)</sup> <u>&rarr;</u> 1<sup>(7)</sup> <u>&rarr;</u>​​​​​​​ <u>0</u><sup>(8)</sup> <u>&rarr;</u> <u>2</u><sup>(12)</sup></code>.</p>
41+
42+
<p><strong>Note:</strong> The notation used is <code>node<sup>(total time)</sup></code>, <code>&rarr;</code> represents forward road, and <code><u>&rarr;</u></code> represents backward road.</p>
43+
</div>
44+
45+
<p><strong class="example">Example 2:</strong></p>
46+
47+
<div class="example-block">
48+
<p><strong>Input:</strong> <span class="example-io">forward = [1,1,1,1], backward = [2,2,2,2], queries = [1,2,3,0]</span></p>
49+
50+
<p><strong>Output:</strong> <span class="example-io">4</span></p>
51+
52+
<p><strong>Explanation:</strong></p>
53+
54+
<p>The path travelled is <code><u>0</u> &rarr;​​​​​​​ <u>1</u> &rarr;​​​​​​​ <u>2</u> &rarr;​​​​​​​ <u>3</u> &rarr; <u>0</u></code>. Each step is in the forward direction and requires 1 second.</p>
55+
</div>
56+
57+
<p>&nbsp;</p>
58+
<p><strong>Constraints:</strong></p>
59+
60+
<ul>
61+
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
62+
<li><code>n == forward.length == backward.length</code></li>
63+
<li><code>1 &lt;= forward[i], backward[i] &lt;= 10<sup>5</sup></code></li>
64+
<li><code>1 &lt;= queries.length &lt;= 10<sup>5</sup></code></li>
65+
<li><code>0 &lt;= queries[i] &lt; n</code></li>
66+
<li><code>queries[i] != queries[i + 1]</code></li>
67+
<li><code>queries[0]</code> is not 0.</li>
68+
</ul>
69+
70+
<!-- description:end -->
71+
72+
## Solutions
73+
74+
<!-- solution:start -->
75+
76+
### Solution 1
77+
78+
<!-- tabs:start -->
79+
80+
#### Python3
81+
82+
```python
83+
84+
```
85+
86+
#### Java
87+
88+
```java
89+
90+
```
91+
92+
#### C++
93+
94+
```cpp
95+
96+
```
97+
98+
#### Go
99+
100+
```go
101+
102+
```
103+
104+
<!-- tabs:end -->
105+
106+
<!-- solution:end -->
107+
108+
<!-- problem:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
comments: true
3+
difficulty: 简单
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3541.Find%20Most%20Frequent%20Vowel%20and%20Consonant/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3541. 找到频率最高的元音和辅音](https://leetcode.cn/problems/find-most-frequent-vowel-and-consonant)
10+
11+
[English Version](/solution/3500-3599/3541.Find%20Most%20Frequent%20Vowel%20and%20Consonant/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个由小写英文字母(<code>'a'</code> 到 <code>'z'</code>)组成的字符串 <code>s</code>。你的任务是找出出现频率&nbsp;<strong>最高&nbsp;</strong>的元音(<code>'a'</code>、<code>'e'</code>、<code>'i'</code>、<code>'o'</code>、<code>'u'</code> 中的一个)和出现频率<strong>最高</strong>的辅音(除元音以外的所有字母),并返回这两个频率之和。</p>
18+
19+
<p><strong>注意</strong>:如果有多个元音或辅音具有相同的最高频率,可以任选其中一个。如果字符串中没有元音或没有辅音,则其频率视为 0。</p>
20+
一个字母 <code>x</code> 的&nbsp;<strong>频率&nbsp;</strong>是它在字符串中出现的次数。
21+
22+
<p>&nbsp;</p>
23+
24+
<p><strong class="example">示例 1:</strong></p>
25+
26+
<div class="example-block">
27+
<p><strong>输入:</strong> <span class="example-io">s = "successes"</span></p>
28+
29+
<p><strong>输出:</strong> <span class="example-io">6</span></p>
30+
31+
<p><strong>解释:</strong></p>
32+
33+
<ul>
34+
<li>元音有:<code>'u'</code> 出现 1 次,<code>'e'</code> 出现 2 次。最大元音频率 = 2。</li>
35+
<li>辅音有:<code>'s'</code> 出现 4 次,<code>'c'</code> 出现 2 次。最大辅音频率 = 4。</li>
36+
<li>输出为 <code>2 + 4 = 6</code>。</li>
37+
</ul>
38+
</div>
39+
40+
<p><strong class="example">示例 2:</strong></p>
41+
42+
<div class="example-block">
43+
<p><strong>输入:</strong> <span class="example-io">s = "aeiaeia"</span></p>
44+
45+
<p><strong>输出:</strong> <span class="example-io">3</span></p>
46+
47+
<p><strong>解释:</strong></p>
48+
49+
<ul>
50+
<li>元音有:<code>'a'</code> 出现 3 次,<code>'e'</code> 出现 2 次,<code>'i'</code> 出现 2 次。最大元音频率 = 3。</li>
51+
<li><code>s</code> 中没有辅音。因此,最大辅音频率 = 0。</li>
52+
<li>输出为 <code>3 + 0 = 3</code>。</li>
53+
</ul>
54+
</div>
55+
56+
<p>&nbsp;</p>
57+
58+
<p><strong>提示:</strong></p>
59+
60+
<ul>
61+
<li><code>1 &lt;= s.length &lt;= 100</code></li>
62+
<li><code>s</code> 只包含小写英文字母</li>
63+
</ul>
64+
65+
<!-- description:end -->
66+
67+
## 解法
68+
69+
<!-- solution:start -->
70+
71+
### 方法一
72+
73+
<!-- tabs:start -->
74+
75+
#### Python3
76+
77+
```python
78+
79+
```
80+
81+
#### Java
82+
83+
```java
84+
85+
```
86+
87+
#### C++
88+
89+
```cpp
90+
91+
```
92+
93+
#### Go
94+
95+
```go
96+
97+
```
98+
99+
<!-- tabs:end -->
100+
101+
<!-- solution:end -->
102+
103+
<!-- problem:end -->

0 commit comments

Comments
 (0)