Skip to content

Commit 2a5c1d4

Browse files
committed
feat: add solutions to lc problems: No.0512,1571
* No.0512.Game Play Analysis II * No.1571.Warehouse Manager
1 parent 79210e6 commit 2a5c1d4

File tree

13 files changed

+124
-61
lines changed

13 files changed

+124
-61
lines changed

solution/0500-0599/0511.Game Play Analysis I/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ Result 表:
6060

6161
```sql
6262
SELECT
63-
player_id, MIN(event_date) first_login
63+
player_id,
64+
MIN(event_date) first_login
6465
FROM
6566
Activity
66-
GROUP BY player_id;
67+
GROUP BY
68+
player_id;
6769
```
6870

6971
<!-- tabs:end -->

solution/0500-0599/0511.Game Play Analysis I/README_EN.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ Activity table:
6161

6262
```sql
6363
SELECT
64-
player_id, MIN(event_date) first_login
64+
player_id,
65+
MIN(event_date) first_login
6566
FROM
6667
Activity
67-
GROUP BY player_id;
68+
GROUP BY
69+
player_id;
6870
```
6971

7072
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
SELECT
2-
player_id, MIN(event_date) first_login
1+
SELECT
2+
player_id,
3+
MIN(event_date) first_login
34
FROM
45
Activity
5-
GROUP BY player_id;
6+
GROUP BY
7+
player_id;

solution/0500-0599/0512.Game Play Analysis II/README.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,22 @@ Result table:
5656
### **SQL**
5757

5858
```sql
59-
59+
# Write your MySQL query statement below
60+
select
61+
player_id,
62+
device_id
63+
from
64+
Activity
65+
where
66+
(player_id, event_date) in (
67+
select
68+
player_id,
69+
min(event_date) event_date
70+
from
71+
Activity
72+
group by
73+
player_id
74+
)
6075
```
6176

6277
<!-- tabs:end -->

solution/0500-0599/0512.Game Play Analysis II/README_EN.md

+16-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,22 @@ Activity table:
6060
### **SQL**
6161

6262
```sql
63-
63+
# Write your MySQL query statement below
64+
select
65+
player_id,
66+
device_id
67+
from
68+
Activity
69+
where
70+
(player_id, event_date) in (
71+
select
72+
player_id,
73+
min(event_date) event_date
74+
from
75+
Activity
76+
group by
77+
player_id
78+
)
6479
```
6580

6681
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Write your MySQL query statement below
2+
select
3+
player_id,
4+
device_id
5+
from
6+
Activity
7+
where
8+
(player_id, event_date) in (
9+
select
10+
player_id,
11+
min(event_date) event_date
12+
from
13+
Activity
14+
group by
15+
player_id
16+
)

solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,17 @@ customer_number 为 '3' 的顾客有两个订单,比顾客 '1' 或者 '2' 都
6666
### **SQL**
6767

6868
```sql
69+
# Write your MySQL query statement below
6970
SELECT
7071
customer_number
7172
FROM
72-
Orders
73-
GROUP BY customer_number
74-
ORDER BY COUNT(customer_number) DESC
75-
LIMIT 1;
73+
orders
74+
GROUP BY
75+
customer_number
76+
ORDER BY
77+
count(1) DESC
78+
LIMIT
79+
1;
7680
```
7781

7882
SQL Server

solution/0500-0599/0586.Customer Placing the Largest Number of Orders/README_EN.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@ So the result is customer_number 3.
6060
### **SQL**
6161

6262
```sql
63+
# Write your MySQL query statement below
6364
SELECT
6465
customer_number
6566
FROM
66-
Orders
67-
GROUP BY customer_number
68-
ORDER BY COUNT(customer_number) DESC
69-
LIMIT 1;
67+
orders
68+
GROUP BY
69+
customer_number
70+
ORDER BY
71+
count(1) DESC
72+
LIMIT
73+
1;
7074
```
7175

7276
SQL Server
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
SELECT
1+
# Write your MySQL query statement below
2+
SELECT
23
customer_number
34
FROM
4-
Orders
5-
GROUP BY customer_number
6-
ORDER BY COUNT(customer_number) DESC
7-
LIMIT 1;
5+
orders
6+
GROUP BY
7+
customer_number
8+
ORDER BY
9+
count(1) DESC
10+
LIMIT
11+
1;

solution/1500-1599/1571.Warehouse Manager/README.md

+12-20
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,18 @@ Id为4的商品(LC-T-Shirt)的存货量为 4x10x20 = 800
9898

9999
<!-- tabs:start -->
100100

101-
### **Python3**
102-
103-
<!-- 这里可写当前语言的特殊实现逻辑 -->
104-
105-
```python
106-
107-
```
108-
109-
### **Java**
110-
111-
<!-- 这里可写当前语言的特殊实现逻辑 -->
112-
113-
```java
114-
115-
```
116-
117-
### **...**
118-
119-
```
120-
101+
### **SQL**
102+
103+
```sql
104+
# Write your MySQL query statement below
105+
SELECT
106+
name AS warehouse_name,
107+
SUM(units * Width * Length * Height) AS volume
108+
FROM
109+
Warehouse w
110+
JOIN Products p ON w.product_id = p.product_id
111+
GROUP BY
112+
name
121113
```
122114

123115
<!-- tabs:end -->

solution/1500-1599/1571.Warehouse Manager/README_EN.md

+12-16
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,18 @@ LCHouse3: 1 unit of LC-T-Shirt.
9494

9595
<!-- tabs:start -->
9696

97-
### **Python3**
98-
99-
```python
100-
101-
```
102-
103-
### **Java**
104-
105-
```java
106-
107-
```
108-
109-
### **...**
110-
111-
```
112-
97+
### **SQL**
98+
99+
```sql
100+
# Write your MySQL query statement below
101+
SELECT
102+
name AS warehouse_name,
103+
SUM(units * Width * Length * Height) AS volume
104+
FROM
105+
Warehouse w
106+
JOIN Products p ON w.product_id = p.product_id
107+
GROUP BY
108+
name
113109
```
114110

115111
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Write your MySQL query statement below
2+
SELECT
3+
name AS warehouse_name,
4+
SUM(units * Width * Length * Height) AS volume
5+
FROM
6+
Warehouse w
7+
JOIN Products p ON w.product_id = p.product_id
8+
GROUP BY
9+
name

solution/2600-2699/2611.Mice and Cheese/README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@
5757

5858
**方法一:贪心 + 排序**
5959

60-
我们可以先将所有奶酪分给第二只老鼠,接下来,考虑将其中 $k$ 块奶酪分给第一只老鼠,那么我们应该如何选择这 $k$ 块奶酪呢?显然,将第 $i$ 块奶酪从第二只老鼠分给第一只老鼠,得分的变化量为 $reward1[i] - reward2[i]$,我们希望这个变化量尽可能大,这样才能使得总得分最大
60+
我们可以先将所有奶酪分给第二只老鼠,因此初始得分为 $\sum_{i=0}^{n-1} reward2[i]$。
6161

62-
因此,我们将奶酪按照 `reward1[i] - reward2[i]` 从大到小排序,前 $k$ 块奶酪由第一只老鼠吃掉,剩下的奶酪由第二只老鼠吃掉,即可得到最大得分
62+
接下来,考虑将其中 $k$ 块奶酪分给第一只老鼠,那么我们应该如何选择这 $k$ 块奶酪呢?显然,将第 $i$ 块奶酪从第二只老鼠分给第一只老鼠,得分的变化量为 $reward1[i] - reward2[i]$,我们希望这个变化量尽可能大,这样才能使得总得分最大
6363

64-
时间复杂度 $O(n \times \log n)$,空间复杂度 $O(n)$。其中 $n$ 为奶酪的数量。
64+
因此,我们将奶酪按照 $reward1[i] - reward2[i]$ 从大到小排序,前 $k$ 块奶酪由第一只老鼠吃掉,剩下的奶酪由第二只老鼠吃掉,即可得到最大得分。也即是说,我们将初始得分加上 $\sum_{i=0}^{k-1} (reward1[i] - reward2[i])$ 即可。
65+
66+
时间复杂度 $O(n \times \log n)$,空间复杂度 $O(\log n)$。其中 $n$ 为奶酪的数量。
6567

6668
相似题目:
6769

0 commit comments

Comments
 (0)