Skip to content

Commit f05cd51

Browse files
author
Chris Wu
committed
no message
1 parent cd00866 commit f05cd51

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

problems/accounts-merge.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def accountsMerge(self, accounts):
1616
for data in accounts:
1717
name = data[0]
1818
visited = set()
19-
stack = [data[1]]
19+
stack = [data[1]] #[2]
2020

2121
if data[1] in merged: continue #[1]
2222

@@ -27,7 +27,7 @@ def accountsMerge(self, accounts):
2727
stack.extend(graph[e])
2828

2929
merged.update(visited)
30-
ans.append([name]+sorted(list(visited)))
30+
ans.append([name]+sorted(list(visited))) #[3]
3131

3232
return ans
3333

@@ -40,8 +40,8 @@ def accountsMerge(self, accounts):
4040
If the first email is already merged to other groups, then other emails will be in another group as well.
4141
So don't need to check.
4242
43-
Second, do a DFS starting from the first email. Put all the connected nodes into visited.
44-
And append it to the ans with name.
43+
Second, do a DFS starting from the first email. Put all the connected nodes into visited. [2]
44+
And append the sorted(visited) to the ans with name. [3]
4545
4646
Let N be the total number of emails. M be the total number of final groups.
4747
Build the graph takes O(N).

0 commit comments

Comments
 (0)