LeetCode solutions

1916. Find Center of Star Graph

My accepted Python solution to LeetCode problem 1916, Find Center of Star Graph, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 40.5MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 40.5MB, accepted 2025-12-29.

python
class Solution:
    def findCenter(self, edges: List[List[int]]) -> int:
        # The center node appears in every edge
        # So it must appear in both the first two edges
        # Time: O(1), Space: O(1)
        if edges[0][0] == edges[1][0] or edges[0][0] == edges[1][1]:
            return edges[0][0]
        return edges[0][1]

Source