MCPcopy
hub / github.com/HuberTRoy/leetCode / findBottomLeftValue

Method findBottomLeftValue

BFS/FindBottomLeftTreeValue.py:72–94  ·  view source on GitHub ↗

:type root: TreeNode :rtype: int

(self, root)

Source from the content-addressed store, hash-verified

70
71class Solution(object):
72 def findBottomLeftValue(self, root):
73 """
74 :type root: TreeNode
75 :rtype: int
76 """
77 waiting_for_access = [root]
78 new_waiting_for_access = []
79 result = root.val
80
81 while 1:
82 while waiting_for_access:
83 node = waiting_for_access.pop()
84
85 if node.right:
86 new_waiting_for_access.append(node.right)
87 result = node.right.val
88 if node.left:
89 new_waiting_for_access.append(node.left)
90 result = node.left.val
91 if not new_waiting_for_access:
92 return result
93 waiting_for_access.extend(new_waiting_for_access[::-1])
94 new_waiting_for_access = []

Callers

nothing calls this directly

Calls 1

popMethod · 0.45

Tested by

no test coverage detected