Skip to content
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

Dev #1136

Merged
merged 3 commits into from
Jul 4, 2023
Merged

Dev #1136

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
4 changes: 2 additions & 2 deletions solution/0100-0199/0176.Second Highest Salary/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Each row of this table contains information about the salary of an employee.

<p>&nbsp;</p>

<p>Write an SQL query to report the second highest salary from the <code>Employee</code> table. If there is no second highest salary, the query should report <code>null</code>.</p>
<p>Find&nbsp;the second highest salary from the <code>Employee</code> table. If there is no second highest salary,&nbsp;return&nbsp;<code>null</code>.</p>

<p>The query result format is in the following example.</p>
<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
4 changes: 2 additions & 2 deletions solution/0100-0199/0177.Nth Highest Salary/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Each row of this table contains information about the salary of an employee.

<p>&nbsp;</p>

<p>Write an SQL query to report the <code>n<sup>th</sup></code> highest salary from the <code>Employee</code> table. If there is no <code>n<sup>th</sup></code> highest salary, the query should report <code>null</code>.</p>
<p>Find the <code>n<sup>th</sup></code> highest salary from the <code>Employee</code> table. If there is no <code>n<sup>th</sup></code> highest salary, return&nbsp;<code>null</code>.</p>

<p>The query result format is in the following example.</p>
<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
4 changes: 2 additions & 2 deletions solution/0100-0199/0178.Rank Scores/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Each row of this table contains the score of a game. Score is a floating point v

<p>&nbsp;</p>

<p>Write an SQL query to rank the scores. The ranking should be calculated according to the following rules:</p>
<p>Find the rank of the scores. The ranking should be calculated according to the following rules:</p>

<ul>
<li>The scores should be ranked from the highest to the lowest.</li>
Expand All @@ -29,7 +29,7 @@ Each row of this table contains the score of a game. Score is a floating point v

<p>Return the result table ordered by <code>score</code> in descending order.</p>

<p>The query result format is in the following example.</p>
<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ Each row of this table indicates the ID of an order and the ID of the customer w

<p>&nbsp;</p>

<p>Write an SQL query to report all customers who never order anything.</p>
<p>Find all customers who never order anything.</p>

<p>Return the result table in <strong>any order</strong>.</p>

<p>The query result format is in the following example.</p>
<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ Each row of this table indicates the ID of a department and its name.

<p>&nbsp;</p>

<p>Write an SQL query to find employees who have the highest salary in each of the departments.</p>
<p>Find employees who have the highest salary in each of the departments.</p>

<p>Return the result table in <strong>any order</strong>.</p>

<p>The query result format is in the following example.</p>
<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
4 changes: 2 additions & 2 deletions solution/0100-0199/0196.Delete Duplicate Emails/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Each row of this table contains an email. The emails will not contain uppercase

<p>&nbsp;</p>

<p>Write an SQL query to <strong>delete</strong> all the duplicate emails, keeping only one unique email with the smallest <code>id</code>. Note that you are supposed to write a <code>DELETE</code> statement and not a <code>SELECT</code> one.</p>
<p><strong>Delete</strong> all the duplicate emails, keeping only one unique email with the smallest <code>id</code>. (For SQL users, please note that you are supposed to write a <code>DELETE</code> statement and not a <code>SELECT</code> one.)</p>

<p>After running your script, the answer shown is the <code>Person</code> table. The driver will first compile and run your piece of code and then show the <code>Person</code> table. The final order of the <code>Person</code> table <strong>does not matter</strong>.</p>

<p>The query result format is in the following example.</p>
<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public:
*/

struct NumMatrix {
// Of size (N + 1) * (M + 1)
// Of size (N + 1) * (M + 1)
prefix_vec: Vec<Vec<i32>>,
n: usize,
m: usize,
Expand All @@ -184,22 +184,22 @@ struct NumMatrix {
}


/**
/**
* `&self` means the method takes an immutable reference.
* If you need a mutable reference, change it to `&mut self` instead.
*/
impl NumMatrix {

fn new(matrix: Vec<Vec<i32>>) -> Self {
NumMatrix {
NumMatrix {
prefix_vec: vec![vec![0; matrix[0].len() + 1]; matrix.len() + 1],
n: matrix.len(),
m: matrix[0].len(),
is_initialized: false,
ref_vec: matrix,
}
}

fn sum_region(&mut self, row1: i32, col1: i32, row2: i32, col2: i32) -> i32 {
if !self.is_initialized {
self.initialize_prefix_vec();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ numMatrix.sumRegion(1, 2, 2, 4); // return 12 (i.e sum of the blue rectangle)

## Solutions

We use $s[i + 1][j + 1]$ to represent the sum of all elements in the upper-left part up to the $i$-th row and $j$-th column, where the indices $i$ and $j$ both start from $0$.
We use $s[i + 1][j + 1]$ to represent the sum of all elements in the upper-left part up to the $i$-th row and $j$-th column, where the indices $i$ and $j$ both start from $0$.

We can derive the following prefix sum formula:

Expand Down Expand Up @@ -166,7 +166,7 @@ public:
*/

struct NumMatrix {
// Of size (N + 1) * (M + 1)
// Of size (N + 1) * (M + 1)
prefix_vec: Vec<Vec<i32>>,
n: usize,
m: usize,
Expand All @@ -175,22 +175,22 @@ public:
}


/**
/**
* `&self` means the method takes an immutable reference.
* If you need a mutable reference, change it to `&mut self` instead.
*/
impl NumMatrix {

fn new(matrix: Vec<Vec<i32>>) -> Self {
NumMatrix {
NumMatrix {
prefix_vec: vec![vec![0; matrix[0].len() + 1]; matrix.len() + 1],
n: matrix.len(),
m: matrix[0].len(),
is_initialized: false,
ref_vec: matrix,
}
}

fn sum_region(&mut self, row1: i32, col1: i32, row2: i32, col2: i32) -> i32 {
if !self.is_initialized {
self.initialize_prefix_vec();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

<!-- 这里写题目描述 -->

<p>给定两个以 <strong>升序排列</strong> 的整数数组 <code>nums1</code> 和<strong> </strong><code>nums2</code><strong>&nbsp;</strong>,&nbsp;以及一个整数 <code>k</code><strong>&nbsp;</strong>。</p>
<p>给定两个以 <strong>非递减顺序排列</strong> 的整数数组 <code>nums1</code> 和<strong> </strong><code>nums2</code><strong>&nbsp;</strong>,&nbsp;以及一个整数 <code>k</code><strong>&nbsp;</strong>。</p>

<p>定义一对值&nbsp;<code>(u,v)</code>,其中第一个元素来自&nbsp;<code>nums1</code>,第二个元素来自 <code>nums2</code><strong>&nbsp;</strong>。</p>

<p>请找到和最小的 <code>k</code>&nbsp;个数对&nbsp;<code>(u<sub>1</sub>,v<sub>1</sub>)</code>, <code>&nbsp;(u<sub>2</sub>,v<sub>2</sub>)</code> &nbsp;... &nbsp;<code>(u<sub>k</sub>,v<sub>k</sub>)</code>&nbsp;。</p>

<p>&nbsp;</p>

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

<pre>
<strong>输入:</strong> nums1 = [1,7,11], nums2 = [2,4,6], k = 3
Expand All @@ -23,7 +23,7 @@
[1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6]
</pre>

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

<pre>
<strong>输入: </strong>nums1 = [1,1,2], nums2 = [1,2,3], k = 2
Expand All @@ -32,7 +32,7 @@
&nbsp; [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3]
</pre>

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

<pre>
<strong>输入: </strong>nums1 = [1,2], nums2 = [3], k = 3
Expand Down
4 changes: 2 additions & 2 deletions solution/0500-0599/0511.Game Play Analysis I/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ Each row is a record of a player who logged in and played a number of games (pos

<p>&nbsp;</p>

<p>Write an SQL query to report the <strong>first login date</strong> for each player.</p>
<p>Find the <strong>first login date</strong> for each player.</p>

<p>Return the result table in <strong>any order</strong>.</p>

<p>The query result format is in the following example.</p>
<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ No employee will be the manager of themself.

<p>&nbsp;</p>

<p>Write an SQL query to report the managers with at least <strong>five direct reports</strong>.</p>
<p>Find the managers with at least <strong>five direct reports</strong>.</p>

<p>Return the result table in <strong>any order</strong>.</p>

<p>The query result format is in the following example.</p>
<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
102 changes: 57 additions & 45 deletions solution/0500-0599/0585.Investments in 2016/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,68 @@

<!-- 这里写题目描述 -->

<p>写一个查询语句,将&nbsp;2016 年 (<strong>TIV_2016</strong>) 所有成功投资的金额加起来,保留 2 位小数。</p>

<p>对于一个投保人,他在 2016 年成功投资的条件是:</p>

<ol>
<li>他在 2015 年的投保额&nbsp;(<strong>TIV_2015</strong>) 至少跟一个其他投保人在 2015 年的投保额相同。</li>
<li>他所在的城市必须与其他投保人都不同(也就是说维度和经度不能跟其他任何一个投保人完全相同)。</li>
</ol>

<p><strong>输入格式:</strong><br>
表&nbsp;<strong><em>insurance</em></strong> 格式如下:</p>

<pre>| Column Name | Type |
|-------------|---------------|
| PID | INTEGER(11) |
| TIV_2015 | NUMERIC(15,2) |
| TIV_2016 | NUMERIC(15,2) |
| LAT | NUMERIC(5,2) |
| LON | NUMERIC(5,2) |
</pre>

<p><strong>PID</strong>&nbsp;字段是投保人的投保编号,&nbsp;<strong>TIV_2015</strong> 是该投保人在2015年的总投保金额,&nbsp;<strong>TIV_2016</strong> 是该投保人在2016年的投保金额,&nbsp;<strong>LAT</strong> 是投保人所在城市的维度,&nbsp;<strong>LON</strong>&nbsp;是投保人所在城市的经度。</p>

<p><strong>样例输入</strong></p>

<pre>| PID | TIV_2015 | TIV_2016 | LAT | LON |
|-----|----------|----------|-----|-----|
<p><code>Insurance</code> 表:</p>

<div class="original__bRMd">
<div>
<pre>
+-------------+-------+
| Column Name | Type |
+-------------+-------+
| pid | int |
| tiv_2015 | float |
| tiv_2016 | float |
| lat | float |
| lon | float |
+-------------+-------+
pid 是这张表的主键。
表中的每一行都包含一条保险信息,其中:
pid 是投保人的投保编号。
tiv_2015 是该投保人在 2015 年的总投保金额,tiv_2016 是该投保人在 2016 年的总投保金额。
lat 是投保人所在城市的纬度。题目数据确保 lat 不为空。
lon 是投保人所在城市的经度。题目数据确保 lon 不为空。</pre>

<p>&nbsp;</p>

<p>请你编写一个 SQL 查询,报告 2016 年 (<code>tiv_2016</code>) 所有满足下述条件的投保人的投保金额之和:</p>

<ul>
<li>他在 2015 年的投保额&nbsp;(<code>tiv_2015</code>) 至少跟一个其他投保人在 2015 年的投保额相同。</li>
<li>他所在的城市必须与其他投保人都不同(也就是说&nbsp;(<code>lat, lon</code>) 不能跟其他任何一个投保人完全相同)。</li>
</ul>

<p><code>tiv_2016</code> 四舍五入的 <strong>两位小数</strong> 。</p>

<p>查询结果格式如下例所示。</p>

<p>&nbsp;</p>

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

<pre>
<strong>输入:</strong>
Insurance 表:
+-----+----------+----------+-----+-----+
| pid | tiv_2015 | tiv_2016 | lat | lon |
+-----+----------+----------+-----+-----+
| 1 | 10 | 5 | 10 | 10 |
| 2 | 20 | 20 | 20 | 20 |
| 3 | 10 | 30 | 20 | 20 |
| 4 | 10 | 40 | 40 | 40 |
</pre>

<p><strong>样例输出</strong></p>

<pre>| TIV_2016 |
|----------|
+-----+----------+----------+-----+-----+
<strong>输出:</strong>
+----------+
| tiv_2016 |
+----------+
| 45.00 |
</pre>

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

<pre>就如最后一个投保人,第一个投保人同时满足两个条件:
1. 他在 2015 年的投保金额 <strong>TIV_2015 </strong>为 &#39;10&#39; ,与第三个和第四个投保人在 2015 年的投保金额相同。
2. 他所在城市的经纬度是独一无二的。

第二个投保人两个条件都不满足。他在 2015 年的投资 <strong>TIV_2015 </strong>与其他任何投保人都不相同。
且他所在城市的经纬度与第三个投保人相同。基于同样的原因,第三个投保人投资失败。

所以返回的结果是第一个投保人和最后一个投保人的 <strong>TIV_2016 </strong>之和,结果是 45 。</pre>
+----------+
<strong>解释:
</strong>表中的第一条记录和最后一条记录都满足两个条件。
tiv_2015 值为 10 与第三条和第四条记录相同,且其位置是唯一的。
第二条记录不符合任何一个条件。其 tiv_2015 与其他投保人不同,并且位置与第三条记录相同,这也导致了第三条记录不符合题目要求。
因此,结果是第一条记录和最后一条记录的 tiv_2016 之和,即 45 。</pre>
</div>
</div>

## 解法

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ This table contains information about the order ID and the customer ID.

<p>&nbsp;</p>

<p>Write an SQL query to find the <code>customer_number</code> for the customer who has placed <strong>the largest number of orders</strong>.</p>
<p>Find the <code>customer_number</code> for the customer who has placed <strong>the largest number of orders</strong>.</p>

<p>The test cases are generated so that <strong>exactly one customer</strong> will have placed more orders than any other customer.</p>

<p>The query result format is in the following example.</p>
<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
4 changes: 2 additions & 2 deletions solution/0500-0599/0595.Big Countries/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ Each row of this table gives information about the name of a country, the contin
<li>it has a population of at least&nbsp;twenty-five million (i.e., <code>25000000</code>).</li>
</ul>

<p>Write an SQL query to report the name, population, and area of the <strong>big countries</strong>.</p>
<p>Find the name, population, and area of the <strong>big countries</strong>.</p>

<p>Return the result table in <strong>any order</strong>.</p>

<p>The query result format is in the following example.</p>
<p>The result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Each row of this table indicates the name of a student and the class in which th

<p>&nbsp;</p>

<p>Write an SQL query to report all the classes that have <strong>at least five students</strong>.</p>
<p>Find all the classes that have <strong>at least five students</strong>.</p>

<p>Return the result table in <strong>any order</strong>.</p>

<p>The query result format is in the following example.</p>
<p>The&nbsp;result format is in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
Expand Down
4 changes: 2 additions & 2 deletions solution/0600-0699/0607.Sales Person/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ Each row of this table contains information about one order. This includes the I

<p>&nbsp;</p>

<p>Write an SQL query to report the names of all the salespersons who did not have any orders related to the company with the name <strong>&quot;RED&quot;</strong>.</p>
<p>Find the names of all the salespersons who did not have any orders related to the company with the name <strong>&quot;RED&quot;</strong>.</p>

<p>Return the result table in <strong>any order</strong>.</p>

<p>The query result format is in the following example.</p>
<p>The result format is in the following example.</p>

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