Created
August 10, 2021 22:50
-
-
Save VXU1230/995f7df0ac4425dc195e841bac98aebc 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 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