Skip to content

feat: add new lc problems #4399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions solution/3500-3599/3540.Minimum Time to Visit All Houses/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3540.Minimum%20Time%20to%20Visit%20All%20Houses/README.md
---

<!-- problem:start -->

# [3540. 访问所有房屋的最短时间 🔒](https://leetcode.cn/problems/minimum-time-to-visit-all-houses)

[English Version](/solution/3500-3599/3540.Minimum%20Time%20to%20Visit%20All%20Houses/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给定两个整数数组&nbsp;<code>forward</code> 和&nbsp;<code>backward</code>,长度都为&nbsp;<code>n</code>。同时给定另一个整数数组&nbsp;<code>queries</code>。</p>

<p>有&nbsp;<code>n</code>&nbsp;个排列为环形的房屋。房屋通过道路以特殊方式相连:</p>

<ul>
<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>
<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>
</ul>

<p>你可以以 <strong>1</strong> 米每秒的速度行走。从房屋&nbsp;0 开始,找到按照&nbsp;<code>queries</code>&nbsp;指定的顺序访问每所房屋的 <strong>最小</strong> 时间。</p>

<p>返回访问房屋所需的 <strong>最短</strong> 总时间。</p>

<p>&nbsp;</p>

<p><strong class="example">示例 1:</strong></p>

<div class="example-block">
<p><span class="example-io"><b>输入:</b>forward = [1,4,4], backward = [4,1,2], queries = [1,2,0,2]</span></p>

<p><b>输出:</b>12</p>

<p><b>解释:</b></p>

<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>

<p><strong>注意:</strong>使用的&nbsp;<code>node<sup>(total time)</sup></code>&nbsp;符号,<code>→</code>&nbsp;表示前向道路,<code><u>→</u></code>&nbsp;表示反向道路。</p>
</div>

<p><strong class="example">示例 2:</strong></p>

<div class="example-block">
<p><strong>输入:</strong><span class="example-io">forward = [1,1,1,1], backward = [2,2,2,2], queries = [1,2,3,0]</span></p>

<p><span class="example-io"><b>输出:</b>4</span></p>

<p><strong>解释:</strong></p>

<p>经过路径是&nbsp;<code><u>0</u> → <u>1</u> → <u>2</u> →​​​​​​​ <u>3</u> → <u>0</u></code>。每一步都在前向方向,需要 1 秒。</p>
</div>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>

<ul>
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>n == forward.length == backward.length</code></li>
<li><code>1 &lt;= forward[i], backward[i] &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= queries.length &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= queries[i] &lt; n</code></li>
<li><code>queries[i] != queries[i + 1]</code></li>
<li><code>queries[0]</code>&nbsp;非 0。</li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
108 changes: 108 additions & 0 deletions solution/3500-3599/3540.Minimum Time to Visit All Houses/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
comments: true
difficulty: Medium
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3540.Minimum%20Time%20to%20Visit%20All%20Houses/README_EN.md
---

<!-- problem:start -->

# [3540. Minimum Time to Visit All Houses 🔒](https://leetcode.com/problems/minimum-time-to-visit-all-houses)

[中文文档](/solution/3500-3599/3540.Minimum%20Time%20to%20Visit%20All%20Houses/README.md)

## Description

<!-- description:start -->

<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>

<p>There are <code>n</code> houses <em>arranged in a circle</em>. The houses are connected via roads in a special arrangement:</p>

<ul>
<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>
<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>
</ul>

<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>

<p>Return the <strong>minimum</strong> total time taken to visit the houses.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">forward = [1,4,4], backward = [4,1,2], queries = [1,2,0,2]</span></p>

<p><strong>Output:</strong> 12</p>

<p><strong>Explanation:</strong></p>

<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>

<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>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<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>

<p><strong>Output:</strong> <span class="example-io">4</span></p>

<p><strong>Explanation:</strong></p>

<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>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>n == forward.length == backward.length</code></li>
<li><code>1 &lt;= forward[i], backward[i] &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= queries.length &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= queries[i] &lt; n</code></li>
<li><code>queries[i] != queries[i + 1]</code></li>
<li><code>queries[0]</code> is not 0.</li>
</ul>

<!-- description:end -->

## Solutions

<!-- solution:start -->

### Solution 1

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3541.Find%20Most%20Frequent%20Vowel%20and%20Consonant/README.md
---

<!-- problem:start -->

# [3541. 找到频率最高的元音和辅音](https://leetcode.cn/problems/find-most-frequent-vowel-and-consonant)

[English Version](/solution/3500-3599/3541.Find%20Most%20Frequent%20Vowel%20and%20Consonant/README_EN.md)

## 题目描述

<!-- description:start -->

<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>

<p><strong>注意</strong>:如果有多个元音或辅音具有相同的最高频率,可以任选其中一个。如果字符串中没有元音或没有辅音,则其频率视为 0。</p>
一个字母 <code>x</code> 的&nbsp;<strong>频率&nbsp;</strong>是它在字符串中出现的次数。

<p>&nbsp;</p>

<p><strong class="example">示例 1:</strong></p>

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "successes"</span></p>

<p><strong>输出:</strong> <span class="example-io">6</span></p>

<p><strong>解释:</strong></p>

<ul>
<li>元音有:<code>'u'</code> 出现 1 次,<code>'e'</code> 出现 2 次。最大元音频率 = 2。</li>
<li>辅音有:<code>'s'</code> 出现 4 次,<code>'c'</code> 出现 2 次。最大辅音频率 = 4。</li>
<li>输出为 <code>2 + 4 = 6</code>。</li>
</ul>
</div>

<p><strong class="example">示例 2:</strong></p>

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "aeiaeia"</span></p>

<p><strong>输出:</strong> <span class="example-io">3</span></p>

<p><strong>解释:</strong></p>

<ul>
<li>元音有:<code>'a'</code> 出现 3 次,<code>'e'</code> 出现 2 次,<code>'i'</code> 出现 2 次。最大元音频率 = 3。</li>
<li><code>s</code> 中没有辅音。因此,最大辅音频率 = 0。</li>
<li>输出为 <code>3 + 0 = 3</code>。</li>
</ul>
</div>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>

<ul>
<li><code>1 &lt;= s.length &lt;= 100</code></li>
<li><code>s</code> 只包含小写英文字母</li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Loading
Loading