Skip to content

Commit d5378e5

Browse files
committed
Time: 1 ms (100.00%), Space: 45.8 MB (45.59%) - LeetHub
1 parent eed015a commit d5378e5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public int findChampion(int n, int[][] edges) {
3+
4+
//Topo sort type concept
5+
int[] indegree = new int[n];
6+
7+
for(int[] edge : edges){
8+
indegree[edge[1]]++;
9+
}
10+
int cnt=0,node=-1;
11+
for(int i=0;i<n;i++){
12+
if(indegree[i]==0){
13+
cnt++;
14+
node=i;
15+
}
16+
}
17+
18+
return (cnt>1)?-1:node;
19+
20+
}
21+
}

0 commit comments

Comments
 (0)