Created
August 10, 2021 22:49
-
-
Save VXU1230/ba890a8ade972ed07d5551df79a4b43f to your computer and use it in GitHub Desktop.
This file contains 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 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