Skip to content

Instantly share code, notes, and snippets.

@aaronshaver
Created April 20, 2022 18:43
Show Gist options
  • Save aaronshaver/ad1df7953d75272b9611bc59b319dde7 to your computer and use it in GitHub Desktop.
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
# 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