Leetcode Problem 1791. Find Center of Star Graph

1791. Find Center of Star Graph

Leetcode Solutions

Finding the Center of a Star Graph

  1. Take the first edge and extract the two nodes, let's call them a and b.
  2. Take the second edge and extract the two nodes, let's call them c and d.
  3. Compare the nodes from the first edge with the nodes from the second edge.
  4. The center node will be the one that is common between the two edges.
  5. If a is equal to either c or d, then a is the center.
  6. If b is equal to either c or d, then b is the center.
  7. Return the center node.
UML Thumbnail

Using a Dictionary to Find the Center

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...