Skip to content

Commit f563f81

Browse files
authored
feat: add solutions to lc problems: No.1777,2679 (doocs#1110)
* No.1777.Product's Price for Each Store * No.2679.Sum in a Matrix
1 parent 9c5b6ae commit f563f81

File tree

8 files changed

+84
-12
lines changed

8 files changed

+84
-12
lines changed

.prettierrc

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"solution/1500-1599/1501.Countries You Can Safely Invest In/Solution.sql",
3232
"solution/1500-1599/1555.Bank Account Summary/Solution.sql",
3333
"solution/1600-1699/1667.Fix Names in a Table/Solution.sql",
34+
"solution/1700-1799/1777.Product's Price for Each Store/Solution.sql",
3435
"solution/1900-1999/1972.First and Last Call On the Same Day/Solution.sql",
3536
"solution/2600-2699/2686.Immediate Food Delivery III/Solution.sql",
3637
"solution/2700-2799/2752.Customers with Maximum Number of Transactions on Consecutive Days/Solution.sql"

solution/1700-1799/1777.Product's Price for Each Store/README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,14 @@ Result 表:
5959
### **SQL**
6060

6161
```sql
62-
62+
# Write your MySQL query statement below
63+
SELECT
64+
product_id,
65+
sum(if(store = 'store1', price, NULL)) AS store1,
66+
sum(if(store = 'store2', price, NULL)) AS store2,
67+
sum(if(store = 'store3', price, NULL)) AS store3
68+
FROM Products
69+
GROUP BY 1;
6370
```
6471

6572
<!-- tabs:end -->

solution/1700-1799/1777.Product's Price for Each Store/README_EN.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,14 @@ Product 1 price&#39;s are 70 for store1, 80 for store3 and, it&#39;s not sold in
6161
### **SQL**
6262

6363
```sql
64-
64+
# Write your MySQL query statement below
65+
SELECT
66+
product_id,
67+
sum(if(store = 'store1', price, NULL)) AS store1,
68+
sum(if(store = 'store2', price, NULL)) AS store2,
69+
sum(if(store = 'store3', price, NULL)) AS store3
70+
FROM Products
71+
GROUP BY 1;
6572
```
6673

6774
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Write your MySQL query statement below
2+
SELECT
3+
product_id,
4+
sum(if(store = 'store1', price, NULL)) AS store1,
5+
sum(if(store = 'store2', price, NULL)) AS store2,
6+
sum(if(store = 'store3', price, NULL)) AS store3
7+
FROM Products
8+
GROUP BY 1;

solution/2600-2699/2679.Sum in a Matrix/README.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ class Solution:
6565
def matrixSum(self, nums: List[List[int]]) -> int:
6666
for row in nums:
6767
row.sort()
68-
n = len(nums[0])
69-
return sum(max(row[j] for row in nums) for j in range(n))
68+
return sum(map(max, zip(*nums)))
7069
```
7170

7271
### **Java**
@@ -139,6 +138,25 @@ func max(a, b int) int {
139138
}
140139
```
141140

141+
### **TypeScript**
142+
143+
```ts
144+
function matrixSum(nums: number[][]): number {
145+
for (const row of nums) {
146+
row.sort((a, b) => a - b);
147+
}
148+
let ans = 0;
149+
for (let j = 0; j < nums[0].length; ++j) {
150+
let mx = 0;
151+
for (const row of nums) {
152+
mx = Math.max(mx, row[j]);
153+
}
154+
ans += mx;
155+
}
156+
return ans;
157+
}
158+
```
159+
142160
### **...**
143161

144162
```

solution/2600-2699/2679.Sum in a Matrix/README_EN.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ class Solution:
4848
def matrixSum(self, nums: List[List[int]]) -> int:
4949
for row in nums:
5050
row.sort()
51-
n = len(nums[0])
52-
return sum(max(row[j] for row in nums) for j in range(n))
51+
return sum(map(max, zip(*nums)))
5352
```
5453

5554
### **Java**
@@ -120,6 +119,25 @@ func max(a, b int) int {
120119
}
121120
```
122121

122+
### **TypeScript**
123+
124+
```ts
125+
function matrixSum(nums: number[][]): number {
126+
for (const row of nums) {
127+
row.sort((a, b) => a - b);
128+
}
129+
let ans = 0;
130+
for (let j = 0; j < nums[0].length; ++j) {
131+
let mx = 0;
132+
for (const row of nums) {
133+
mx = Math.max(mx, row[j]);
134+
}
135+
ans += mx;
136+
}
137+
return ans;
138+
}
139+
```
140+
123141
### **...**
124142

125143
```
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
class Solution:
2-
def matrixSum(self, nums: List[List[int]]) -> int:
3-
for row in nums:
4-
row.sort()
5-
n = len(nums[0])
6-
return sum(max(row[j] for row in nums) for j in range(n))
1+
class Solution:
2+
def matrixSum(self, nums: List[List[int]]) -> int:
3+
for row in nums:
4+
row.sort()
5+
return sum(map(max, zip(*nums)))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
function matrixSum(nums: number[][]): number {
2+
for (const row of nums) {
3+
row.sort((a, b) => a - b);
4+
}
5+
let ans = 0;
6+
for (let j = 0; j < nums[0].length; ++j) {
7+
let mx = 0;
8+
for (const row of nums) {
9+
mx = Math.max(mx, row[j]);
10+
}
11+
ans += mx;
12+
}
13+
return ans;
14+
}

0 commit comments

Comments
 (0)