Skip to content

Instantly share code, notes, and snippets.

@VXU1230
Created August 10, 2021 22:50
Show Gist options
  • Save VXU1230/995f7df0ac4425dc195e841bac98aebc to your computer and use it in GitHub Desktop.
Save VXU1230/995f7df0ac4425dc195e841bac98aebc to your computer and use it in GitHub Desktop.
def iddfs():
root = get_root()
res = float("inf")
def iddfs_search(node, depth, limit):
if depth <= limit and node is not None:
val = node.val
if val >= 10:
nonlocal res
res = min(res, depth)
else:
iddfs_search(node.left, depth + 1, limit)
iddfs_search(node.right, depth + 1, limit)
for limit in range(1, 5):
print("max depth: ", limit)
iddfs_search(root, 0, limit)
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