Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ tags:
<pre>
<strong>Input:</strong> strs = [&quot;abc&quot;,&quot;xyz&quot;]
<strong>Output:</strong> &quot;zyxcba&quot;
<strong>Explanation:</strong> You can get the looped string &quot;-abcxyz-&quot;, &quot;-abczyx-&quot;, &quot;-cbaxyz-&quot;, &quot;-cbazyx-&quot;, where &#39;-&#39; represents the looped status.
<strong>Explanation:</strong> You can get the looped string &quot;-abcxyz-&quot;, &quot;-abczyx-&quot;, &quot;-cbaxyz-&quot;, &quot;-cbazyx-&quot;, where &#39;-&#39; represents the looped status.
The answer string came from the fourth looped one, where you could cut from the middle character &#39;a&#39; and get &quot;zyxcba&quot;.
</pre>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tags:
<li><code>i &lt; j</code>&nbsp;且&nbsp;<code>nums[i] &gt; nums[j]</code></li>
</ul>

<p>请你返回&nbsp;<code>[0, 1, 2, ..., n - 1]</code>&nbsp;的&nbsp;<span data-keyword="permutation">排列</span> <code>perm</code>&nbsp;的数目,满足对 <strong>所有</strong>&nbsp;的&nbsp;<code>requirements[i]</code>&nbsp;都有&nbsp;<code>perm[0..end<sub>i</sub>]</code>&nbsp;恰好有&nbsp;<code>cnt<sub>i</sub></code>&nbsp;个逆序对。</p>
<p>请你返回&nbsp;<code>[0, 1, 2, ..., n - 1]</code>&nbsp;的&nbsp;<span data-keyword="permutation">排列</span> <code>perm</code>&nbsp;的数目,满足对 <strong>所有</strong>&nbsp;的&nbsp;<code>requirements[i]</code>&nbsp;都满足&nbsp;<code>perm[0..end<sub>i</sub>]</code>&nbsp;中恰好有&nbsp;<code>cnt<sub>i</sub></code>&nbsp;个逆序对。</p>

<p>由于答案可能会很大,将它对&nbsp;<code>10<sup>9</sup> + 7</code>&nbsp;<strong>取余</strong>&nbsp;后返回。</p>

Expand Down
53 changes: 27 additions & 26 deletions solution/3300-3399/3308.Find Top Performing Driver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ tags:

<!-- problem:start -->

# [3308. Find Top Performing Driver 🔒](https://leetcode.cn/problems/find-top-performing-driver)
# [3308. 寻找表现最佳的司机 🔒](https://leetcode.cn/problems/find-top-performing-driver)

[English Version](/solution/3300-3399/3308.Find%20Top%20Performing%20Driver/README_EN.md)

## 题目描述

<!-- description:start -->

<p>Table: <font face="monospace"><code>Drivers</code></font></p>
<p>表:<font face="monospace"><code>Drivers</code></font></p>

<pre>
+--------------+---------+
Expand All @@ -28,11 +28,11 @@ tags:
| experience | int |
| accidents | int |
+--------------+---------+
(driver_id) is the unique key for this table.
Each row includes a driver&#39;s ID, their name, age, years of driving experience, and the number of accidents they&rsquo;ve had.
(driver_id) 是这张表的唯一主键。
每一行包含一个司机 ID,他们的名字,年龄,驾龄年数,以及事故数。
</pre>

<p>Table: <font face="monospace"><code>Vehicles</code></font></p>
<p>表:<font face="monospace"><code>Vehicles</code></font></p>

<pre>
+--------------+---------+
Expand All @@ -42,11 +42,11 @@ Each row includes a driver&#39;s ID, their name, age, years of driving experienc
| fuel_type | varchar |
| mileage | int |
+--------------+---------+
(vehicle_id, driver_id, fuel_type) is the unique key for this table.
Each row includes the vehicle&#39;s ID, the driver who operates it, the model, fuel type, and mileage.
(vehicle_id, driver_id, fuel_type) 是这张表的唯一主键。
每一行包含机动车 ID,驾驶员,车型,动力类型和里程数。
</pre>

<p>Table: <font face="monospace"><code>Trips</code></font></p>
<p>表:<font face="monospace"><code>Trips</code></font></p>

<pre>
+--------------+---------+
Expand All @@ -56,29 +56,30 @@ Each row includes the vehicle&#39;s ID, the driver who operates it, the model, f
| duration | int |
| rating | int |
+--------------+---------+
(trip_id) is the unique key for this table.
Each row includes a trip&#39;s ID, the vehicle used, the distance covered (in miles), the trip duration (in minutes), and the passenger&#39;s rating (1-5).
(trip_id) 是这张表的唯一主键。
每一行包含行程 ID,使用的机动车,覆盖的距离(以米计),行程市场(以分钟计),以及乘客评分(1-5)。
</pre>

<p>Uber is analyzing drivers based on their trips. Write a solution to find the <strong>top-performing driver</strong> for <strong>each fuel type</strong> based on the following criteria:</p>
<p>优步正在基于司机的行程分析他们的情况。编写一个解决方案,根据下列标准来找到 <strong>每种动力类型</strong> 中&nbsp;<strong>表现最好的司机</strong></p>

<ol>
<li>A driver&#39;s performance is calculated as the <strong>average rating</strong> across all their trips. Average rating should be rounded to <code>2</code> decimal places.</li>
<li>If two drivers have the same average rating, the driver with the <strong>longer total distance</strong> traveled should be ranked higher.</li>
<li>If there is <strong>still a tie</strong>, choose the driver with the <strong>fewest accidents</strong>.</li>
<li>一个司机的表现由他们行程的 <strong>平均评分</strong>&nbsp;计算。平均评分应该舍入到&nbsp;<code>2</code>&nbsp;位小数。</li>
<li>如果两个司机有相同的平均评分,<strong>里程数更多</strong>&nbsp;的司机评分更高。</li>
<li>如果 <strong>依旧持平</strong>,选择 <strong>事故数最少</strong>&nbsp;的司机。</li>
</ol>

<p>Return <em>the result table ordered by</em> <code>fuel_type</code> <em>in </em><strong>ascending</strong><em> order.</em></p>
<p>返回结果表以&nbsp;<code>fuel_type</code> <strong>升序&nbsp;</strong>排序。</p>

<p>The result format is in the following example.</p>
<p>结果格式如下所示。</p>

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

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

<div class="example-block">
<p><strong>Input:</strong></p>
<p><strong>输入:</strong></p>

<p><code>Drivers</code> table:</p>
<p><code>Drivers</code> 表:</p>

<pre class="example-io">
+-----------+----------+-----+------------+-----------+
Expand All @@ -90,7 +91,7 @@ Each row includes a trip&#39;s ID, the vehicle used, the distance covered (in mi
+-----------+----------+-----+------------+-----------+
</pre>

<p><code>Vehicles</code> table:</p>
<p><code>Vehicles</code> 表:</p>

<pre class="example-io">
+------------+-----------+---------+-----------+---------+
Expand All @@ -102,7 +103,7 @@ Each row includes a trip&#39;s ID, the vehicle used, the distance covered (in mi
+------------+-----------+---------+-----------+---------+
</pre>

<p><code>Trips</code> table:</p>
<p><code>Trips</code> 表:</p>

<pre class="example-io">
+---------+------------+----------+----------+--------+
Expand All @@ -117,7 +118,7 @@ Each row includes a trip&#39;s ID, the vehicle used, the distance covered (in mi
+---------+------------+----------+----------+--------+
</pre>

<p><strong>Output:</strong></p>
<p><strong>输出:</strong></p>

<pre class="example-io">
+-----------+-----------+--------+----------+
Expand All @@ -128,14 +129,14 @@ Each row includes a trip&#39;s ID, the vehicle used, the distance covered (in mi
+-----------+-----------+--------+----------+
</pre>

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

<ul>
<li>For fuel type <code>Gasoline</code>, both Alice (Driver 1) and Charlie (Driver 3) have trips. Charlie has an average rating of 5.0, while Alice has 4.5. Therefore, Charlie is selected.</li>
<li>For fuel type <code>Electric</code>, Bob (Driver 2) is the only driver with an average rating of 4.5, so he is selected.</li>
<li>对于动力类型&nbsp;<code>Gasoline</code>Alice(司机 1)和&nbsp;Charlie(司机 3)有行程。Charlie 平均评分为 5.0,而 Alice 4.5。因此,选择 Charlie</li>
<li>对于动力类型&nbsp;<code>Electric</code>Bob(司机 2)是唯一的司机,评分为 4.5,因此选择他。</li>
</ul>

<p>The output table is ordered by <code>fuel_type</code> in ascending order.</p>
<p>输出表以&nbsp;<code>fuel_type</code>&nbsp;升序排序。</p>
</div>

<!-- description:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,11 @@ tags:

<ul>
<li>清空字符串&nbsp;<code>dfsStr</code>&nbsp;并调用&nbsp;<code>dfs(i)</code>&nbsp;。</li>
<li>如果结果字符串&nbsp;<code>dfsStr</code>&nbsp;是一个 <strong>回文串</strong>&nbsp;,<code>answer[i]</code>&nbsp;为&nbsp;<code>true</code>&nbsp;,否则&nbsp;<code>answer[i]</code>&nbsp;为&nbsp;<code>false</code>&nbsp;。</li>
<li>如果结果字符串&nbsp;<code>dfsStr</code>&nbsp;是一个 <span data-keyword="palindrome-string">回文串</span>&nbsp;,<code>answer[i]</code>&nbsp;为&nbsp;<code>true</code>&nbsp;,否则&nbsp;<code>answer[i]</code>&nbsp;为&nbsp;<code>false</code>&nbsp;。</li>
</ul>

<p>请你返回字符串&nbsp;<code>answer</code>&nbsp;。</p>

<p><strong>回文串</strong>&nbsp;指的是一个字符串从前往后与从后往前是一模一样的。</p>

<p>&nbsp;</p>

<p><strong class="example">示例 1:</strong></p>
Expand Down
61 changes: 31 additions & 30 deletions solution/3300-3399/3328.Find Cities in Each State II/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ tags:

<!-- problem:start -->

# [3328. Find Cities in Each State II 🔒](https://leetcode.cn/problems/find-cities-in-each-state-ii)
# [3328. 查找每个州的城市 II 🔒](https://leetcode.cn/problems/find-cities-in-each-state-ii)

[English Version](/solution/3300-3399/3328.Find%20Cities%20in%20Each%20State%20II/README_EN.md)

## 题目描述

<!-- description:start -->

<p>Table: <code>cities</code></p>
<p>表:<code>cities</code></p>

<pre>
+-------------+---------+
Expand All @@ -25,29 +25,30 @@ tags:
| state | varchar |
| city | varchar |
+-------------+---------+
(state, city) is the combination of columns with unique values for this table.
Each row of this table contains the state name and the city name within that state.
(state, city) 是这张表中值互不相同的列的组合。
这张表的每一行包含州名和其中的城市名。
</pre>

<p>Write a solution to find <strong>all the cities</strong> in <strong>each state</strong> and analyze them based on the following requirements:</p>
<p>编写一个解决方案来找到 <strong>每个州</strong>&nbsp;中的 <strong>所有城市</strong>&nbsp;并且根据下列条件分析它们:</p>

<ul>
<li>Combine all cities into a <strong>comma-separated</strong> string for each state.</li>
<li>Only include states that have <strong>at least</strong> <code>3</code> cities.</li>
<li>Only include states where <strong>at least one city</strong> starts with the <strong>same letter as the state name</strong>.</li>
<li>用 <b>逗号分隔</b>&nbsp;字符串组合每一个州的所有城市。</li>
<li>只显示有 <strong>至少</strong>&nbsp;<code>3</code>&nbsp;个城市的州。</li>
<li>只显示&nbsp;<strong>至少有一个城市</strong>&nbsp;以与 <strong>州名相同字母开头</strong>&nbsp;的州。</li>
</ul>

<p>Return <em>the result table ordered by</em> <em>the count of matching-letter cities in <strong>descending</strong> order</em>&nbsp;<em>and then by state name in <strong>ascending</strong> order</em>.</p>
<p>返回结果表以字母匹配城市的数量 <strong>降序</strong> 排序,然后按州名称 <strong>升序</strong> 排序的结果表。</p>

<p>The result format is in the following example.</p>
<p>结果格式如下所示。</p>

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

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

<div class="example-block">
<p><strong>Input:</strong></p>
<p><strong>输入:</strong></p>

<p>cities table:</p>
<p>cities 表:</p>

<pre class="example-io">
+--------------+---------------+
Expand All @@ -71,58 +72,58 @@ Each row of this table contains the state name and the city name within that sta
+--------------+---------------+
</pre>

<p><strong>Output:</strong></p>
<p><strong>输出:</strong></p>

<pre class="example-io">
+-------------+-------------------------------------------+-----------------------+
| state | cities | matching_letter_count |
+-------------+-------------------------------------------+-----------------------+
| Pennsylvania| Philadelphia, Pittsburgh, Pottstown | 3 |
| Texas | Dallas, Taylor, Temple, Tyler | 2 |
| Texas | Dallas, Taylor, Temple, Tyler | 3 |
| New York | Buffalo, Newark, New York City, Rochester | 2 |
+-------------+-------------------------------------------+-----------------------+
</pre>

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

<ul>
<li><strong>Pennsylvania</strong>:

<ul>
<li>Has 3 cities (meets minimum requirement)</li>
<li>All 3 cities start with &#39;P&#39; (same as state)</li>
<li> 3 个城市(符合最低条件)</li>
<li>所有的 3 个城市都以 'P' 开头(与州相同)</li>
<li>matching_letter_count = 3</li>
</ul>
</li>
<li><strong>Texas</strong>:
<ul>
<li>Has 4 cities (meets minimum requirement)</li>
<li>2 cities (Temple, Tyler) start with &#39;T&#39; (same as state)</li>
<li>matching_letter_count = 2</li>
<li> 4 个城市(符合最低条件)</li>
<li>3 个城市 (Taylor, Temple, Tyler) 以 'T' 开头(与州相同)</li>
<li>matching_letter_count = 3</li>
</ul>
</li>
<li><strong>New York</strong>:
<ul>
<li>Has 4 cities (meets minimum requirement)</li>
<li>2 cities (Newark, New York City) start with &#39;N&#39; (same as state)</li>
<li> 4 个城市(符合最低条件)</li>
<li>2 个城市 (Newark, New York City) 以 'N' 开头(与州相同)</li>
<li>matching_letter_count = 2</li>
</ul>
</li>
<li><strong>California</strong> is not included in the output because:
<li><strong>California</strong> 没有包含在输出表,因为:
<ul>
<li>Although it has 4 cities (meets minimum requirement)</li>
<li>No cities start with &#39;C&#39; (doesn&#39;t meet the matching letter requirement)</li>
<li>尽管它有 4 个城市(符合最低条件)</li>
<li>没有城市以 'C' 开头(不符合字母匹配条件)</li>
</ul>
</li>

</ul>

<p><strong>Note:</strong></p>
<p><strong>注意:</strong></p>

<ul>
<li>Results are ordered by matching_letter_count in descending order</li>
<li>When matching_letter_count is the same (Texas and New York both have 2), they are ordered by state name alphabetically</li>
<li>Cities in each row are ordered alphabetically</li>
<li>结果以 matching_letter_count 降序排序。</li>
<li> matching_letter_count 持平(Texas New York 都为 2),按州名字母序排序。</li>
<li>每一行的城市也以字母序排序。</li>
</ul>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Each row of this table contains the state name and the city name within that sta
| state | cities | matching_letter_count |
+-------------+-------------------------------------------+-----------------------+
| Pennsylvania| Philadelphia, Pittsburgh, Pottstown | 3 |
| Texas | Dallas, Taylor, Temple, Tyler | 2 |
| Texas | Dallas, Taylor, Temple, Tyler | 3 |
| New York | Buffalo, Newark, New York City, Rochester | 2 |
+-------------+-------------------------------------------+-----------------------+
</pre>
Expand All @@ -97,8 +97,8 @@ Each row of this table contains the state name and the city name within that sta
<li><strong>Texas</strong>:
<ul>
<li>Has 4 cities (meets minimum requirement)</li>
<li>2 cities (Temple, Tyler) start with &#39;T&#39; (same as state)</li>
<li>matching_letter_count = 2</li>
<li>3 cities (Taylor, Temple, Tyler) start with &#39;T&#39; (same as state)</li>
<li>matching_letter_count = 3</li>
</ul>
</li>
<li><strong>New York</strong>:
Expand Down
Loading
Loading