Skip to content

Commit ce7aec9

Browse files
authored
Create 2924. Find Champion II (#644)
2 parents a1f538f + 84cb638 commit ce7aec9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

2924. Find Champion II

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int findChampion(int n, vector<vector<int>>& edges) {
4+
vector<int>in(n, 0);
5+
int sz = edges.size();
6+
for (int i = 0; i < sz; i++) {
7+
in[edges[i][1]]++;
8+
}
9+
int result = -1;
10+
for (int i = 0; i < n; i++) {
11+
if (in[i] == 0) {
12+
if (result >= 0) return -1;
13+
result = i;
14+
}
15+
}
16+
return result;
17+
}
18+
};

0 commit comments

Comments
 (0)