Skip to content

Instantly share code, notes, and snippets.

@VXU1230
Created August 10, 2021 22:49
Show Gist options
  • Save VXU1230/ba890a8ade972ed07d5551df79a4b43f to your computer and use it in GitHub Desktop.
Save VXU1230/ba890a8ade972ed07d5551df79a4b43f to your computer and use it in GitHub Desktop.
def dfs():
root = get_root()
res = float("inf")
def dfs_search(node, depth):
if node is not None:
val = node.val
if val >= 10:
nonlocal res
res = min(res, depth)
else:
dfs_search(node.left, depth+1)
dfs_search(node.right, depth + 1)
dfs_search(root, 0)
if res < float("inf"):
return res
return -1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment