forked from rui-yan/LeetCode-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cclauss
committed
Apr 1, 2018
1 parent
9495772
commit 65b3ea4
Showing
131 changed files
with
792 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,20 +16,20 @@ | |
# The accounts themselves can be returned in any order. | ||
# | ||
# Example 1: | ||
# Input: | ||
# Input: | ||
# accounts = [["John", "[email protected]", "[email protected]"], | ||
# ["John", "[email protected]"], | ||
# ["John", "[email protected]", "[email protected]"], | ||
# ["Mary", "[email protected]"]] | ||
# Output: [["John", '[email protected]', '[email protected]', '[email protected]'], | ||
# ["John", "[email protected]"], ["Mary", "[email protected]"]] | ||
# | ||
# Explanation: | ||
# Explanation: | ||
# The first and third John's are the same person as they have the common email "[email protected]". | ||
# The second John and Mary are different people as none of their email addresses are used by other accounts. | ||
# We could return these lists in any order, | ||
# for example the answer [['Mary', '[email protected]'], | ||
# ['John', '[email protected]'], | ||
# ['John', '[email protected]'], | ||
# ['John', '[email protected]', '[email protected]', '[email protected]']] | ||
# would still be accepted. | ||
# | ||
|
@@ -39,14 +39,17 @@ | |
# The length of accounts[i] will be in the range [1, 10]. | ||
# The length of accounts[i][j] will be in the range [1, 30]. | ||
|
||
import collections | ||
|
||
|
||
class UnionFind(object): | ||
def __init__(self): | ||
self.set = [] | ||
|
||
def get_id(self): | ||
self.set.append(len(self.set)) | ||
return len(self.set)-1 | ||
|
||
def find_set(self, x): | ||
if self.set[x] != x: | ||
self.set[x] = self.find_set(self.set[x]) # path compression. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.