Find Champion II

Medium

Topics
Graph

There are n teams labeled 0..n-1 in a tournament. Each directed edge [u, v] means team u is stronger than team v. A team is the champion if no other team is stronger than it. Return the label of the unique champion, or -1 if it is not unique.

Example 1

Input:  n = 3, edges = [[0,1],[1,2]]
Output: 0

Example 2

Input:  n = 2, edges = [[0,1],[1,0]]
Output: -1

Constraints

  • 1 <= n <= 100
  • edges[i] = [u, v] with u != v.
Run ⌘' · Submit ⌘⏎