We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f17c5c9 commit 9c1520fCopy full SHA for 9c1520f
513. Find Bottom Left Tree Value/513. Find Bottom Left Tree Value.py
@@ -34,18 +34,19 @@
34
# self.left = left
35
# self.right = right
36
class Solution:
37
- def findBottomLeftValue(self, root: TreeNode) -> int:
+ def findBottomLeftValue(self, root: Optional[TreeNode]) -> int:
38
+ if not root: return None
39
q = collections.deque()
40
q.append(root)
- bottom_left = root.val
41
+ result = None
42
while q:
- length = len(q)
43
- for i in range(length):
+ n = len(q)
44
+ for x in range(n):
45
node = q.popleft()
- if i == 0:
46
- bottom_left = node.val
+ if x == 0:
47
+ result = node.val
48
if node.left:
49
q.append(node.left)
50
if node.right:
51
q.append(node.right)
- return bottom_left
52
+ return result
0 commit comments