Leetcode Problem 2924. Find Champion II

2924. Find Champion II

Leetcode Solutions

Counting In-Degrees to Find the Champion

  1. Initialize an array indegree of length n to store the in-degree count for each node.
  2. Iterate over each edge in edges and increment the in-degree count of the destination node.
  3. Initialize a variable champion to -1 to store the index of the potential champion.
  4. Iterate over the indegree array to check for nodes with zero in-degree.
  5. If a node with zero in-degree is found, check if champion is already set to a node index. If so, return -1 as there is no unique champion.
  6. If champion is not set, assign the current node index to champion.
  7. After the loop, if champion is not -1, return champion; otherwise, return -1.
UML Thumbnail

Using a Set to Track Non-Champions

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...