Created
August 10, 2021 22:49
-
-
Save VXU1230/9fda4a4e89ae13ebd9865d6657345954 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 bfs(): | |
root = get_root() | |
queue = collections.deque() | |
queue.appendleft((root, 0)) | |
res = -1 | |
while queue: | |
node, depth = queue.pop() | |
if node.val >= 10: | |
res = depth | |
break | |
if node.left: | |
queue.appendleft((node.left, depth+1)) | |
if node.right: | |
queue.appendleft((node.right, depth+1)) | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment