Skip to content

Instantly share code, notes, and snippets.

@VXU1230
Created August 10, 2021 22:49
Show Gist options
  • Save VXU1230/9fda4a4e89ae13ebd9865d6657345954 to your computer and use it in GitHub Desktop.
Save VXU1230/9fda4a4e89ae13ebd9865d6657345954 to your computer and use it in GitHub Desktop.
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