Skip to content

Commit adbc216

Browse files
yanglbmeidoocs
andauthored
feat: add weekly contest 370 (doocs#1927)
* feat: add weekly contest 370 * chore: optimised images with calibre/image-actions --------- Co-authored-by: Doocs Bot <doocs-bot@outlook.com>
1 parent afbd192 commit adbc216

File tree

21 files changed

+834
-31
lines changed

21 files changed

+834
-31
lines changed

solution/0300-0399/0350.Intersection of Two Arrays II/README_EN.md

-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ public class Solution {
246246
}
247247
```
248248

249-
250249
### **...**
251250

252251
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# [2923. 找到冠军 I](https://leetcode.cn/problems/find-champion-i)
2+
3+
[English Version](/solution/2900-2999/2923.Find%20Champion%20I/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>一场比赛中共有 <code>n</code> 支队伍,按从 <code>0</code> 到&nbsp; <code>n - 1</code> 编号。</p>
10+
11+
<p>给你一个下标从 <strong>0</strong> 开始、大小为 <code>n * n</code> 的二维布尔矩阵 <code>grid</code> 。对于满足&nbsp;<code>0 &lt;= i, j &lt;= n - 1</code> 且 <code>i != j</code> 的所有 <code>i, j</code> :如果 <code>grid[i][j] == 1</code>,那么 <code>i</code> 队比 <code>j</code> 队 <strong>强</strong> ;否则,<code>j</code> 队比 <code>i</code> 队 <strong>强</strong> 。</p>
12+
13+
<p>在这场比赛中,如果不存在某支强于 <code>a</code> 队的队伍,则认为 <code>a</code> 队将会是 <strong>冠军</strong> 。</p>
14+
15+
<p>返回这场比赛中将会成为冠军的队伍。</p>
16+
17+
<p>&nbsp;</p>
18+
19+
<p><strong>示例 1:</strong></p>
20+
21+
<pre>
22+
<strong>输入:</strong>grid = [[0,1],[0,0]]
23+
<strong>输出:</strong>0
24+
<strong>解释:</strong>比赛中有两支队伍。
25+
grid[0][1] == 1 表示 0 队比 1 队强。所以 0 队是冠军。
26+
</pre>
27+
28+
<p><strong>示例 2:</strong></p>
29+
30+
<pre>
31+
<strong>输入:</strong>grid = [[0,0,1],[1,0,1],[0,0,0]]
32+
<strong>输出:</strong>1
33+
<strong>解释:</strong>比赛中有三支队伍。
34+
grid[1][0] == 1 表示 1 队比 0 队强。
35+
grid[1][2] == 1 表示 1 队比 2 队强。
36+
所以 1 队是冠军。
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
41+
<p><strong>提示:</strong></p>
42+
43+
<ul>
44+
<li><code>n == grid.length</code></li>
45+
<li><code>n == grid[i].length</code></li>
46+
<li><code>2 &lt;= n &lt;= 100</code></li>
47+
<li><code>grid[i][j]</code> 的值为 <code>0</code> 或 <code>1</code></li>
48+
<li>对于满足&nbsp;<code>i != j</code> 的所有 <code>i, j</code> ,<code>grid[i][j] != grid[j][i]</code> 均成立</li>
49+
<li>生成的输出满足:如果 <code>a</code> 队比 <code>b</code> 队强,<code>b</code> 队比 <code>c</code> 队强,那么 <code>a</code> 队比 <code>c</code> 队强</li>
50+
</ul>
51+
52+
## 解法
53+
54+
<!-- 这里可写通用的实现逻辑 -->
55+
56+
<!-- tabs:start -->
57+
58+
### **Python3**
59+
60+
<!-- 这里可写当前语言的特殊实现逻辑 -->
61+
62+
```python
63+
64+
```
65+
66+
### **Java**
67+
68+
<!-- 这里可写当前语言的特殊实现逻辑 -->
69+
70+
```java
71+
72+
```
73+
74+
### **C++**
75+
76+
```cpp
77+
78+
```
79+
80+
### **Go**
81+
82+
```go
83+
84+
```
85+
86+
### **...**
87+
88+
```
89+
90+
```
91+
92+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# [2923. Find Champion I](https://leetcode.com/problems/find-champion-i)
2+
3+
[中文文档](/solution/2900-2999/2923.Find%20Champion%20I/README.md)
4+
5+
## Description
6+
7+
<p>There are <code>n</code> teams numbered from <code>0</code> to <code>n - 1</code> in a tournament.</p>
8+
9+
<p>Given a <strong>0-indexed</strong> 2D boolean matrix <code>grid</code> of size <code>n * n</code>. For all <code>i, j</code> that <code>0 &lt;= i, j &lt;= n - 1</code> and <code>i != j</code> team <code>i</code> is <strong>stronger</strong> than team <code>j</code> if <code>grid[i][j] == 1</code>, otherwise, team <code>j</code> is <strong>stronger</strong> than team <code>i</code>.</p>
10+
11+
<p>Team <code>a</code> will be the <strong>champion</strong> of the tournament if there is no team <code>b</code> that is stronger than team <code>a</code>.</p>
12+
13+
<p>Return <em>the team that will be the champion of the tournament.</em></p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong class="example">Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input:</strong> grid = [[0,1],[0,0]]
20+
<strong>Output:</strong> 0
21+
<strong>Explanation:</strong> There are two teams in this tournament.
22+
grid[0][1] == 1 means that team 0 is stronger than team 1. So team 0 will be the champion.
23+
</pre>
24+
25+
<p><strong class="example">Example 2:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> grid = [[0,0,1],[1,0,1],[0,0,0]]
29+
<strong>Output:</strong> 1
30+
<strong>Explanation:</strong> There are three teams in this tournament.
31+
grid[1][0] == 1 means that team 1 is stronger than team 0.
32+
grid[1][2] == 1 means that team 1 is stronger than team 2.
33+
So team 1 will be the champion.
34+
</pre>
35+
36+
<p>&nbsp;</p>
37+
<p><strong>Constraints:</strong></p>
38+
39+
<ul>
40+
<li><code>n == grid.length</code></li>
41+
<li><code>n == grid[i].length</code></li>
42+
<li><code>2 &lt;= n &lt;= 100</code></li>
43+
<li><code>grid[i][j]</code> is either <code>0</code> or <code>1</code>.</li>
44+
<li>For all <code>i, j</code> that <code>i != j</code>, <code>grid[i][j] != grid[j][i]</code>.</li>
45+
<li>The input is generated such that if team <code>a</code> is stronger than team <code>b</code> and team <code>b</code> is stronger than team <code>c</code>, then team <code>a</code> is stronger than team <code>c</code>.</li>
46+
</ul>
47+
48+
## Solutions
49+
50+
<!-- tabs:start -->
51+
52+
### **Python3**
53+
54+
```python
55+
56+
```
57+
58+
### **Java**
59+
60+
```java
61+
62+
```
63+
64+
### **C++**
65+
66+
```cpp
67+
68+
```
69+
70+
### **Go**
71+
72+
```go
73+
74+
```
75+
76+
### **...**
77+
78+
```
79+
80+
```
81+
82+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# [2924. 找到冠军 II](https://leetcode.cn/problems/find-champion-ii)
2+
3+
[English Version](/solution/2900-2999/2924.Find%20Champion%20II/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>一场比赛中共有 <code>n</code> 支队伍,按从 <code>0</code> 到&nbsp; <code>n - 1</code> 编号。每支队伍也是 <strong>有向无环图(DAG)</strong> 上的一个节点。</p>
10+
11+
<p>给你一个整数 <code>n</code> 和一个下标从 <strong>0</strong> 开始、长度为 <code>m</code> 的二维整数数组 <code>edges</code> 表示这个有向无环图,其中 <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> 表示图中存在一条从 <code>u<sub>i</sub></code> 队到 <code>v<sub>i</sub></code> 队的有向边。</p>
12+
13+
<p>从 <code>a</code> 队到 <code>b</code> 队的有向边意味着 <code>a</code> 队比 <code>b</code> 队 <strong>强</strong> ,也就是 <code>b</code> 队比 <code>a</code> 队 <strong>弱</strong> 。</p>
14+
15+
<p>在这场比赛中,如果不存在某支强于 <code>a</code> 队的队伍,则认为 <code>a</code> 队将会是 <strong>冠军</strong> 。</p>
16+
17+
<p>如果这场比赛存在 <strong>唯一</strong> 一个冠军,则返回将会成为冠军的队伍。否则,返回<em> </em><code>-1</code><em> 。</em></p>
18+
19+
<p><strong>注意</strong></p>
20+
21+
<ul>
22+
<li><strong>环</strong> 是形如 <code>a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>n</sub>, a<sub>n+1</sub></code> 的一个序列,且满足:节点 <code>a<sub>1</sub></code> 与节点 <code>a<sub>n+1</sub></code> 是同一个节点;节点 <code>a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>n</sub></code> 互不相同;对于范围&nbsp;<code>[1, n]</code> 中的每个 <code>i</code> ,均存在一条从节点 <code>a<sub>i</sub></code> 到节点 <code>a<sub>i+1</sub></code> 的有向边。</li>
23+
<li><strong>有向无环图</strong> 是不存在任何环的有向图。</li>
24+
</ul>
25+
26+
<p>&nbsp;</p>
27+
28+
<p><strong class="example">示例 1:</strong></p>
29+
30+
<p><img height="300" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2924.Find%20Champion%20II/images/graph-3.png" width="300" /></p>
31+
32+
<pre>
33+
<strong>输入:</strong>n = 3, edges = [[0,1],[1,2]]
34+
<strong>输出:</strong>0
35+
<strong>解释:</strong>1 队比 0 队弱。2 队比 1 队弱。所以冠军是 0 队。
36+
</pre>
37+
38+
<p><strong class="example">示例 2:</strong></p>
39+
40+
<p><img height="300" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2924.Find%20Champion%20II/images/graph-4.png" width="300" /></p>
41+
42+
<pre>
43+
<strong>输入:</strong>n = 4, edges = [[0,2],[1,3],[1,2]]
44+
<strong>输出:</strong>-1
45+
<strong>解释:</strong>2 队比 0 队和 1 队弱。3 队比 1 队弱。但是 1 队和 0 队之间不存在强弱对比。所以答案是 -1 。
46+
</pre>
47+
48+
<p>&nbsp;</p>
49+
50+
<p><strong>提示:</strong></p>
51+
52+
<ul>
53+
<li><code>1 &lt;= n &lt;= 100</code></li>
54+
<li><code>m == edges.length</code></li>
55+
<li><code>0 &lt;= m &lt;= n * (n - 1) / 2</code></li>
56+
<li><code>edges[i].length == 2</code></li>
57+
<li><code>0 &lt;= edge[i][j] &lt;= n - 1</code></li>
58+
<li><code>edges[i][0] != edges[i][1]</code></li>
59+
<li>生成的输入满足:如果 <code>a</code> 队比 <code>b</code> 队强,就不存在 <code>b</code> 队比 <code>a</code> 队强</li>
60+
<li>生成的输入满足:如果 <code>a</code> 队比 <code>b</code> 队强,<code>b</code> 队比 <code>c</code> 队强,那么 <code>a</code> 队比 <code>c</code> 队强</li>
61+
</ul>
62+
63+
## 解法
64+
65+
<!-- 这里可写通用的实现逻辑 -->
66+
67+
<!-- tabs:start -->
68+
69+
### **Python3**
70+
71+
<!-- 这里可写当前语言的特殊实现逻辑 -->
72+
73+
```python
74+
75+
```
76+
77+
### **Java**
78+
79+
<!-- 这里可写当前语言的特殊实现逻辑 -->
80+
81+
```java
82+
83+
```
84+
85+
### **C++**
86+
87+
```cpp
88+
89+
```
90+
91+
### **Go**
92+
93+
```go
94+
95+
```
96+
97+
### **...**
98+
99+
```
100+
101+
```
102+
103+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# [2924. Find Champion II](https://leetcode.com/problems/find-champion-ii)
2+
3+
[中文文档](/solution/2900-2999/2924.Find%20Champion%20II/README.md)
4+
5+
## Description
6+
7+
<p>There are <code>n</code> teams numbered from <code>0</code> to <code>n - 1</code> in a tournament; each team is also a node in a <strong>DAG</strong>.</p>
8+
9+
<p>You are given the integer <code>n</code> and a <strong>0-indexed</strong> 2D integer array <code>edges</code> of length <code><font face="monospace">m</font></code> representing the <strong>DAG</strong>, where <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>]</code> indicates that there is a directed edge from team <code>u<sub>i</sub></code> to team <code>v<sub>i</sub></code> in the graph.</p>
10+
11+
<p>A directed edge from <code>a</code> to <code>b</code> in the graph means that team <code>a</code> is <strong>stronger</strong> than team <code>b</code> and team <code>b</code> is <strong>weaker</strong> than team <code>a</code>.</p>
12+
13+
<p>Team <code>a</code> will be the <strong>champion</strong> of the tournament if there is no team <code>b</code> that is <strong>stronger</strong> than team <code>a</code>.</p>
14+
15+
<p>Return <em>the team that will be the <strong>champion</strong> of the tournament if there is a <strong>unique</strong> champion, otherwise, return </em><code>-1</code><em>.</em></p>
16+
17+
<p><strong>Notes</strong></p>
18+
19+
<ul>
20+
<li>A <strong>cycle</strong> is a series of nodes <code>a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>n</sub>, a<sub>n+1</sub></code> such that node <code>a<sub>1</sub></code> is the same node as node <code>a<sub>n+1</sub></code>, the nodes <code>a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>n</sub></code> are distinct, and there is a directed edge from the node <code>a<sub>i</sub></code> to node <code>a<sub>i+1</sub></code> for every <code>i</code> in the range <code>[1, n]</code>.</li>
21+
<li>A <strong>DAG</strong> is a directed graph that does not have any <strong>cycle</strong>.</li>
22+
</ul>
23+
24+
<p>&nbsp;</p>
25+
<p><strong class="example">Example 1:</strong></p>
26+
27+
<p><img height="300" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2924.Find%20Champion%20II/images/graph-3.png" width="300" /></p>
28+
29+
<pre>
30+
<strong>Input:</strong> n = 3, edges = [[0,1],[1,2]]
31+
<strong>Output:</strong> 0
32+
<strong>Explanation: </strong>Team 1 is weaker than team 0. Team 2 is weaker than team 1. So the champion is team 0.
33+
</pre>
34+
35+
<p><strong class="example">Example 2:</strong></p>
36+
37+
<p><img height="300" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/2900-2999/2924.Find%20Champion%20II/images/graph-4.png" width="300" /></p>
38+
39+
<pre>
40+
<strong>Input:</strong> n = 4, edges = [[0,2],[1,3],[1,2]]
41+
<strong>Output:</strong> -1
42+
<strong>Explanation:</strong> Team 2 is weaker than team 0 and team 1. Team 3 is weaker than team 1. But team 1 and team 0 are not weaker than any other teams. So the answer is -1.
43+
</pre>
44+
45+
<p>&nbsp;</p>
46+
<p><strong>Constraints:</strong></p>
47+
48+
<ul>
49+
<li><code>1 &lt;= n &lt;= 100</code></li>
50+
<li><code>m == edges.length</code></li>
51+
<li><code>0 &lt;= m &lt;= n * (n - 1) / 2</code></li>
52+
<li><code>edges[i].length == 2</code></li>
53+
<li><code>0 &lt;= edge[i][j] &lt;= n - 1</code></li>
54+
<li><code>edges[i][0] != edges[i][1]</code></li>
55+
<li>The input is generated such that if team <code>a</code> is stronger than team <code>b</code>, team <code>b</code> is not stronger than team <code>a</code>.</li>
56+
<li>The input is generated such that if team <code>a</code> is stronger than team <code>b</code> and team <code>b</code> is stronger than team <code>c</code>, then team <code>a</code> is stronger than team <code>c</code>.</li>
57+
</ul>
58+
59+
## Solutions
60+
61+
<!-- tabs:start -->
62+
63+
### **Python3**
64+
65+
```python
66+
67+
```
68+
69+
### **Java**
70+
71+
```java
72+
73+
```
74+
75+
### **C++**
76+
77+
```cpp
78+
79+
```
80+
81+
### **Go**
82+
83+
```go
84+
85+
```
86+
87+
### **...**
88+
89+
```
90+
91+
```
92+
93+
<!-- tabs:end -->
Loading
Loading

0 commit comments

Comments
 (0)