1class Solution:2def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]:3# create the map4adj = collections.defaultdict(list)5for a, b in adjacentPairs:6adj[a].append(b)7adj[b].append(a)89# find the start num10start = adjacentPairs[0][0]11for k, v in adj.items():12if len(v) == 1:13start = k14break1516# dfs to connect the graph17nums = []18seen = set()1920def dfs(num):21seen.add(num)22for next_num in adj[num]:23if next_num in seen:24continue25dfs(next_num)26nums.append(num)2728dfs(start)29return nums