Skip to content

Instantly share code, notes, and snippets.

@vmarois
Created June 6, 2021 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmarois/917491d682aa65f90c3af099909fc2bf to your computer and use it in GitHub Desktop.
Save vmarois/917491d682aa65f90c3af099909fc2bf to your computer and use it in GitHub Desktop.
def dfs(root: TreeNode) -> TreeNode:
stack = []
while root or stack:
while root:
stack.append(root)
root = root.left
root = stack.pop()
print('Processing {}'.format(root.val))
root = root.right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment