Skip to content

Commit 76dc15a

Browse files
committed
feat: add solutions to lc problems: No.1596,1831
* No.1596.The Most Frequently Ordered Products for Each Customer * No.1831.Maximum Transaction Each Day
1 parent 7e289d3 commit 76dc15a

File tree

7 files changed

+138
-44
lines changed

7 files changed

+138
-44
lines changed

solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README.md

+26-17
Original file line numberDiff line numberDiff line change
@@ -126,26 +126,35 @@ John (customer 5) 没有订购过商品, 所以我们并没有把 John 包含在
126126

127127
<!-- tabs:start -->
128128

129-
### **Python3**
129+
### **SQL**
130130

131131
<!-- 这里可写当前语言的特殊实现逻辑 -->
132132

133-
```python
134-
135-
```
136-
137-
### **Java**
138-
139-
<!-- 这里可写当前语言的特殊实现逻辑 -->
140-
141-
```java
142-
143-
```
144-
145-
### **...**
146-
147-
```
148-
133+
```sql
134+
# Write your MySQL query statement below
135+
select
136+
customer_id,
137+
p.product_id,
138+
p.product_name
139+
from
140+
(
141+
select
142+
customer_id,
143+
product_id,
144+
rank() over(
145+
partition by customer_id
146+
order by
147+
count(1) desc
148+
) rk
149+
from
150+
Orders
151+
group by
152+
customer_id,
153+
product_id
154+
) o
155+
join Products p on o.product_id = p.product_id
156+
where
157+
rk = 1;
149158
```
150159

151160
<!-- tabs:end -->

solution/1500-1599/1596.The Most Frequently Ordered Products for Each Customer/README_EN.md

+27-16
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,33 @@ John (customer 5) did not order anything, so we do not include them in the resul
122122

123123
<!-- tabs:start -->
124124

125-
### **Python3**
126-
127-
```python
128-
129-
```
130-
131-
### **Java**
132-
133-
```java
134-
135-
```
136-
137-
### **...**
138-
139-
```
140-
125+
### **SQL**
126+
127+
```sql
128+
# Write your MySQL query statement below
129+
select
130+
customer_id,
131+
p.product_id,
132+
p.product_name
133+
from
134+
(
135+
select
136+
customer_id,
137+
product_id,
138+
rank() over(
139+
partition by customer_id
140+
order by
141+
count(1) desc
142+
) rk
143+
from
144+
Orders
145+
group by
146+
customer_id,
147+
product_id
148+
) o
149+
join Products p on o.product_id = p.product_id
150+
where
151+
rk = 1;
141152
```
142153

143154
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Write your MySQL query statement below
2+
select
3+
customer_id,
4+
p.product_id,
5+
p.product_name
6+
from
7+
(
8+
select
9+
customer_id,
10+
product_id,
11+
rank() over(
12+
partition by customer_id
13+
order by
14+
count(1) desc
15+
) rk
16+
from
17+
Orders
18+
group by
19+
customer_id,
20+
product_id
21+
) o
22+
join Products p on o.product_id = p.product_id
23+
where
24+
rk = 1;

solution/1800-1899/1831.Maximum Transaction Each Day/README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,25 @@ Result table:
7171
<!-- 这里可写当前语言的特殊实现逻辑 -->
7272

7373
```sql
74-
74+
# Write your MySQL query statement below
75+
select
76+
transaction_id
77+
from
78+
(
79+
select
80+
transaction_id,
81+
rank() over(
82+
partition by date_format(day, '%Y-%m-%d')
83+
order by
84+
amount desc
85+
) rk
86+
from
87+
Transactions
88+
order by
89+
transaction_id
90+
) t
91+
where
92+
rk = 1
7593
```
7694

7795
<!-- tabs:end -->

solution/1800-1899/1831.Maximum Transaction Each Day/README_EN.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,25 @@ We order the result table by transaction_id after collecting these IDs.
6767
### **SQL**
6868

6969
```sql
70-
70+
# Write your MySQL query statement below
71+
select
72+
transaction_id
73+
from
74+
(
75+
select
76+
transaction_id,
77+
rank() over(
78+
partition by date_format(day, '%Y-%m-%d')
79+
order by
80+
amount desc
81+
) rk
82+
from
83+
Transactions
84+
order by
85+
transaction_id
86+
) t
87+
where
88+
rk = 1
7189
```
7290

7391
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Write your MySQL query statement below
2+
select
3+
transaction_id
4+
from
5+
(
6+
select
7+
transaction_id,
8+
rank() over(
9+
partition by date_format(day, '%Y-%m-%d')
10+
order by
11+
amount desc
12+
) rk
13+
from
14+
Transactions
15+
order by
16+
transaction_id
17+
) t
18+
where
19+
rk = 1

solution/2400-2499/2460.Apply Operations to an Array/README.md

+4-9
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,10 @@ class Solution {
111111
}
112112
}
113113
int[] ans = new int[n];
114-
int j = 0;
115-
for (int i = 0; i < n; ++i) {
116-
if (nums[i] != 0) {
117-
ans[j++] = nums[i];
118-
}
119-
}
120-
for (int i = 0; i < n; ++i) {
121-
if (nums[i] == 0) {
122-
ans[j++] = nums[i];
114+
int i = 0;
115+
for (int x : nums) {
116+
if (x > 0) {
117+
ans[i++] = x;
123118
}
124119
}
125120
return ans;

0 commit comments

Comments
 (0)