Created
April 20, 2022 18:43
-
-
Save aaronshaver/ad1df7953d75272b9611bc59b319dde7 to your computer and use it in GitHub Desktop.
Example of using difference() to get all members in one set that aren't in the other set
This file contains hidden or 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
# https://leetcode.com/problems/destination-city/submissions/ | |
class Solution: | |
def destCity(self, paths: List[List[str]]) -> str: | |
candidates = set() | |
rejects = set() | |
for path in paths: | |
candidates.add(path[1]) | |
rejects.add(path[0]) | |
return list(candidates.difference(rejects))[0] # in candidates but not in rejects |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment