Skip to content

Commit 7e5479a

Browse files
committed
feat: add new lc problems
1 parent d2533be commit 7e5479a

File tree

29 files changed

+10430
-8782
lines changed

29 files changed

+10430
-8782
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# [2174. Remove All Ones With Row and Column Flips II](https://leetcode-cn.com/problems/remove-all-ones-with-row-and-column-flips-ii)
2+
3+
[English Version](/solution/2100-2199/2174.Remove%20All%20Ones%20With%20Row%20and%20Column%20Flips%20II/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> <strong>binary</strong> matrix <code>grid</code>.</p>
10+
11+
<p>In one operation, you can choose any <code>i</code> and <code>j</code> that meet the following conditions:</p>
12+
13+
<ul>
14+
<li><code>0 &lt;= i &lt; m</code></li>
15+
<li><code>0 &lt;= j &lt; n</code></li>
16+
<li><code>grid[i][j] == 1</code></li>
17+
</ul>
18+
19+
<p>and change the values of <strong>all</strong> cells in row <code>i</code> and column <code>j</code> to zero.</p>
20+
21+
<p>Return <em>the <strong>minimum</strong> number of operations needed to remove all </em><code>1</code><em>&#39;s from </em><code>grid</code><em>.</em></p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong>Example 1:</strong></p>
25+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2174.Remove%20All%20Ones%20With%20Row%20and%20Column%20Flips%20II/images/image-20220213162716-1.png" style="width: 709px; height: 200px;" />
26+
<pre>
27+
<strong>Input:</strong> grid = [[1,1,1],[1,1,1],[0,1,0]]
28+
<strong>Output:</strong> 2
29+
<strong>Explanation:</strong>
30+
In the first operation, change all cell values of row 1 and column 1 to zero.
31+
In the second operation, change all cell values of row 0 and column 0 to zero.
32+
</pre>
33+
34+
<p><strong>Example 2:</strong></p>
35+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2174.Remove%20All%20Ones%20With%20Row%20and%20Column%20Flips%20II/images/image-20220213162737-2.png" style="width: 734px; height: 200px;" />
36+
<pre>
37+
<strong>Input:</strong> grid = [[0,1,0],[1,0,1],[0,1,0]]
38+
<strong>Output:</strong> 2
39+
<strong>Explanation:</strong>
40+
In the first operation, change all cell values of row 1 and column 0 to zero.
41+
In the second operation, change all cell values of row 2 and column 1 to zero.
42+
Note that we cannot perform an operation using row 1 and column 1 because grid[1][1] != 1.
43+
</pre>
44+
45+
<p><strong>Example 3:</strong></p>
46+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2174.Remove%20All%20Ones%20With%20Row%20and%20Column%20Flips%20II/images/image-20220213162752-3.png" style="width: 156px; height: 150px;" />
47+
<pre>
48+
<strong>Input:</strong> grid = [[0,0],[0,0]]
49+
<strong>Output:</strong> 0
50+
<strong>Explanation:</strong>
51+
There are no 1&#39;s to remove so return 0.
52+
</pre>
53+
54+
<p>&nbsp;</p>
55+
<p><strong>Constraints:</strong></p>
56+
57+
<ul>
58+
<li><code>m == grid.length</code></li>
59+
<li><code>n == grid[i].length</code></li>
60+
<li><code>1 &lt;= m, n &lt;= 15</code></li>
61+
<li><code>1 &lt;= m * n &lt;= 15</code></li>
62+
<li><code>grid[i][j]</code> is either <code>0</code> or <code>1</code>.</li>
63+
</ul>
64+
65+
66+
## 解法
67+
68+
<!-- 这里可写通用的实现逻辑 -->
69+
70+
<!-- tabs:start -->
71+
72+
### **Python3**
73+
74+
<!-- 这里可写当前语言的特殊实现逻辑 -->
75+
76+
```python
77+
78+
```
79+
80+
### **Java**
81+
82+
<!-- 这里可写当前语言的特殊实现逻辑 -->
83+
84+
```java
85+
86+
```
87+
88+
### **TypeScript**
89+
90+
```ts
91+
92+
```
93+
94+
### **...**
95+
96+
```
97+
98+
```
99+
100+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# [2174. Remove All Ones With Row and Column Flips II](https://leetcode.com/problems/remove-all-ones-with-row-and-column-flips-ii)
2+
3+
[中文文档](/solution/2100-2199/2174.Remove%20All%20Ones%20With%20Row%20and%20Column%20Flips%20II/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> <code>m x n</code> <strong>binary</strong> matrix <code>grid</code>.</p>
8+
9+
<p>In one operation, you can choose any <code>i</code> and <code>j</code> that meet the following conditions:</p>
10+
11+
<ul>
12+
<li><code>0 &lt;= i &lt; m</code></li>
13+
<li><code>0 &lt;= j &lt; n</code></li>
14+
<li><code>grid[i][j] == 1</code></li>
15+
</ul>
16+
17+
<p>and change the values of <strong>all</strong> cells in row <code>i</code> and column <code>j</code> to zero.</p>
18+
19+
<p>Return <em>the <strong>minimum</strong> number of operations needed to remove all </em><code>1</code><em>&#39;s from </em><code>grid</code><em>.</em></p>
20+
21+
<p>&nbsp;</p>
22+
<p><strong>Example 1:</strong></p>
23+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2174.Remove%20All%20Ones%20With%20Row%20and%20Column%20Flips%20II/images/image-20220213162716-1.png" style="width: 709px; height: 200px;" />
24+
<pre>
25+
<strong>Input:</strong> grid = [[1,1,1],[1,1,1],[0,1,0]]
26+
<strong>Output:</strong> 2
27+
<strong>Explanation:</strong>
28+
In the first operation, change all cell values of row 1 and column 1 to zero.
29+
In the second operation, change all cell values of row 0 and column 0 to zero.
30+
</pre>
31+
32+
<p><strong>Example 2:</strong></p>
33+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2174.Remove%20All%20Ones%20With%20Row%20and%20Column%20Flips%20II/images/image-20220213162737-2.png" style="width: 734px; height: 200px;" />
34+
<pre>
35+
<strong>Input:</strong> grid = [[0,1,0],[1,0,1],[0,1,0]]
36+
<strong>Output:</strong> 2
37+
<strong>Explanation:</strong>
38+
In the first operation, change all cell values of row 1 and column 0 to zero.
39+
In the second operation, change all cell values of row 2 and column 1 to zero.
40+
Note that we cannot perform an operation using row 1 and column 1 because grid[1][1] != 1.
41+
</pre>
42+
43+
<p><strong>Example 3:</strong></p>
44+
<img src="https://cdn.jsdelivr.net/gh/doocs/leetcode@main/solution/2100-2199/2174.Remove%20All%20Ones%20With%20Row%20and%20Column%20Flips%20II/images/image-20220213162752-3.png" style="width: 156px; height: 150px;" />
45+
<pre>
46+
<strong>Input:</strong> grid = [[0,0],[0,0]]
47+
<strong>Output:</strong> 0
48+
<strong>Explanation:</strong>
49+
There are no 1&#39;s to remove so return 0.
50+
</pre>
51+
52+
<p>&nbsp;</p>
53+
<p><strong>Constraints:</strong></p>
54+
55+
<ul>
56+
<li><code>m == grid.length</code></li>
57+
<li><code>n == grid[i].length</code></li>
58+
<li><code>1 &lt;= m, n &lt;= 15</code></li>
59+
<li><code>1 &lt;= m * n &lt;= 15</code></li>
60+
<li><code>grid[i][j]</code> is either <code>0</code> or <code>1</code>.</li>
61+
</ul>
62+
63+
64+
## Solutions
65+
66+
<!-- tabs:start -->
67+
68+
### **Python3**
69+
70+
```python
71+
72+
```
73+
74+
### **Java**
75+
76+
```java
77+
78+
```
79+
80+
### **TypeScript**
81+
82+
```ts
83+
84+
```
85+
86+
### **...**
87+
88+
```
89+
90+
```
91+
92+
<!-- tabs:end -->
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# [2175. The Change in Global Rankings](https://leetcode-cn.com/problems/the-change-in-global-rankings)
2+
3+
[English Version](/solution/2100-2199/2175.The%20Change%20in%20Global%20Rankings/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Table: <code>TeamPoints</code></p>
10+
11+
<pre>
12+
+-------------+---------+
13+
| Column Name | Type |
14+
+-------------+---------+
15+
| team_id | int |
16+
| name | varchar |
17+
| points | int |
18+
+-------------+---------+
19+
team_id is the primary key for this table.
20+
Each row of this table contains the ID of a national team, the name of the country it represents, and the points it has in the global rankings. No two teams will represent the same country.
21+
</pre>
22+
23+
<p>&nbsp;</p>
24+
25+
<p>Table: <code>PointsChange</code></p>
26+
27+
<pre>
28+
+---------------+------+
29+
| Column Name | Type |
30+
+---------------+------+
31+
| team_id | int |
32+
| points_change | int |
33+
+---------------+------+
34+
team_id is the primary key for this table.
35+
Each row of this table contains the ID of a national team and the change in its points in the global rankings.
36+
points_change can be:
37+
- 0: indicates no change in points.
38+
- positive: indicates an increase in points.
39+
- negative: indicates a decrease in points.
40+
Each team_id that appears in TeamPoints will also appear in this table.
41+
</pre>
42+
43+
<p>&nbsp;</p>
44+
45+
<p>The <strong>global ranking</strong> of a national team is its rank after sorting all the teams by their points <strong>in descending order</strong>. If two teams have the same points, we break the tie by sorting them by their name <strong>in lexicographical order</strong>.</p>
46+
47+
<p>The points of each national team should be updated based on its corresponding <code>points_change</code> value.</p>
48+
49+
<p>Write an SQL query to calculate the change in the global rankings after updating each team&#39;s points.</p>
50+
51+
<p>Return the result table in <strong>any order</strong>.</p>
52+
53+
<p>The query result format is in the following example.</p>
54+
55+
<p>&nbsp;</p>
56+
<p><strong>Example 1:</strong></p>
57+
58+
<pre>
59+
<strong>Input:</strong>
60+
TeamPoints table:
61+
+---------+-------------+--------+
62+
| team_id | name | points |
63+
+---------+-------------+--------+
64+
| 3 | Algeria | 1431 |
65+
| 1 | Senegal | 2132 |
66+
| 2 | New Zealand | 1402 |
67+
| 4 | Croatia | 1817 |
68+
+---------+-------------+--------+
69+
PointsChange table:
70+
+---------+---------------+
71+
| team_id | points_change |
72+
+---------+---------------+
73+
| 3 | 399 |
74+
| 2 | 0 |
75+
| 4 | 13 |
76+
| 1 | -22 |
77+
+---------+---------------+
78+
<strong>Output:</strong>
79+
+---------+-------------+-----------+
80+
| team_id | name | rank_diff |
81+
+---------+-------------+-----------+
82+
| 1 | Senegal | 0 |
83+
| 4 | Croatia | -1 |
84+
| 3 | Algeria | 1 |
85+
| 2 | New Zealand | 0 |
86+
+---------+-------------+-----------+
87+
<strong>Explanation:</strong>
88+
The global rankings were as follows:
89+
+---------+-------------+--------+------+
90+
| team_id | name | points | rank |
91+
+---------+-------------+--------+------+
92+
| 1 | Senegal | 2132 | 1 |
93+
| 4 | Croatia | 1817 | 2 |
94+
| 3 | Algeria | 1431 | 3 |
95+
| 2 | New Zealand | 1402 | 4 |
96+
+---------+-------------+--------+------+
97+
After updating the points of each team, the rankings became the following:
98+
+---------+-------------+--------+------+
99+
| team_id | name | points | rank |
100+
+---------+-------------+--------+------+
101+
| 1 | Senegal | 2110 | 1 |
102+
| 3 | Algeria | 1830 | 2 |
103+
| 4 | Croatia | 1830 | 3 |
104+
| 2 | New Zealand | 1402 | 4 |
105+
+---------+-------------+--------+------+
106+
Since after updating the points Algeria and Croatia have the same points, they are ranked according to their lexicographic order.
107+
Senegal lost 22 points but their rank did not change.
108+
Croatia gained 13 points but their rank decreased by one.
109+
Algeria gained 399 points and their rank increased by one.
110+
New Zealand did not gain or lose points and their rank did not change.
111+
</pre>
112+
113+
## 解法
114+
115+
<!-- 这里可写通用的实现逻辑 -->
116+
117+
<!-- tabs:start -->
118+
119+
### **SQL**
120+
121+
<!-- 这里可写当前语言的特殊实现逻辑 -->
122+
123+
```sql
124+
125+
```
126+
127+
<!-- tabs:end -->

0 commit comments

Comments
 (0)