#2924
Medium Algorithms Find champion ii
Graph Theory
70.3% acceptance
Feb 25, 2026
595
49
There are n teams numbered from 0 to n - 1 in a tournament; each team is also a node in a DAG.
You are given the integer n and a 0-indexed 2D integer array edges of length m representing the DAG,
where edges[i] = [ui, vi] indicates that there is a directed edge from team ui to team vi in the graph.
A directed edge from a to b means team a is stronger than team b.
Team a will be the champion if there is no team b that is stronger than team a.
Return the team that will be the champion if there is a unique champion, otherwise return -1.
Solution
Rust
Time O(n)
Space O(n)
impl Solution {
pub fn find_champion(n: i32, edges: Vec<Vec<i32>>) -> i32 {
let n = n as usize;
let mut in_degree = vec![0usize; n];
for e in &edges {
in_degree[e[1] as usize] += 1;
}
let zeros: Vec<usize> = (0..n).filter(|&i| in_degree[i] == 0).collect();
if zeros.len() == 1 { zeros[0] as i32 } else { -1 }
}
}