Skip to content

Commit f317559

Browse files
committed
Runtime: 2248 ms (Top 15.65%) | Memory: 166 MB (Top 35.87%)
1 parent 6963bc1 commit f317559

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1+
// Runtime: 2248 ms (Top 15.65%) | Memory: 166 MB (Top 35.87%)
12
class Solution:
23
def restoreArray(self, adjacentPairs: List[List[int]]) -> List[int]:
3-
# create the map
4+
# create the map
45
adj = collections.defaultdict(list)
56
for a, b in adjacentPairs:
67
adj[a].append(b)
78
adj[b].append(a)
89

9-
# find the start num
10+
# find the start num
1011
start = adjacentPairs[0][0]
1112
for k, v in adj.items():
1213
if len(v) ==1:
1314
start = k
1415
break
15-
16-
# dfs to connect the graph
16+
17+
# dfs to connect the graph
1718
nums=[]
1819
seen = set()
1920
def dfs(num):
2021
seen.add(num)
2122
for next_num in adj[num]:
2223
if next_num in seen: continue
2324
dfs(next_num)
24-
nums.append(num)
25+
nums.append(num)
2526
dfs(start)
2627
return nums
27-

0 commit comments

Comments
 (0)