Created
April 23, 2020 20:47
-
-
Save pyrofolium/9246985b174e47e1db1bf38994489a2e to your computer and use it in GitHub Desktop.
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
| def traverse(x: List[Tuple[int, int]]) -> Optional[List[int]]: | |
| if len(x) == 0: | |
| return [] | |
| not_leaves = {l: True for (l, r) in x if r is not None} | |
| leaves = {i: True for j in x for i in j if i not in not_leaves and i is not None} | |
| new_x = [(l, None if r in leaves else r) for (l, r) in x if l in not_leaves] | |
| recursion = traverse(new_x) | |
| return [i for i in leaves] + recursion if len(new_x) < x and recursion is not None else None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment