Skip to main content

Uncategorized

A holding area for graph problems that don't yet belong to a named pattern section. As patterns emerge, these get promoted into their own sections.

1791. Find Center of Star Graph​

Easy·
3 Approaches
class Solution:
def findCenter(self, edges: List[List[int]]) -> int:
counter = collections.defaultdict(int)
for a, b in edges:
counter[a] += 1
counter[b] += 1
for node, degree in counter.items():
if degree == len(counter) - 1:
return node