File tree 1 file changed +4
-4
lines changed 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ def accountsMerge(self, accounts):
16
16
for data in accounts :
17
17
name = data [0 ]
18
18
visited = set ()
19
- stack = [data [1 ]]
19
+ stack = [data [1 ]] #[2]
20
20
21
21
if data [1 ] in merged : continue #[1]
22
22
@@ -27,7 +27,7 @@ def accountsMerge(self, accounts):
27
27
stack .extend (graph [e ])
28
28
29
29
merged .update (visited )
30
- ans .append ([name ]+ sorted (list (visited )))
30
+ ans .append ([name ]+ sorted (list (visited ))) #[3]
31
31
32
32
return ans
33
33
@@ -40,8 +40,8 @@ def accountsMerge(self, accounts):
40
40
If the first email is already merged to other groups, then other emails will be in another group as well.
41
41
So don't need to check.
42
42
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]
45
45
46
46
Let N be the total number of emails. M be the total number of final groups.
47
47
Build the graph takes O(N).
You can’t perform that action at this time.
0 commit comments