513. Find Bottom Left Tree Value
- Find Bottom Left Tree Value python solution
题目描述
Given a binary tree, find the leftmost value in the last row of the tree.
解析
持续递归,就是速度有点慢。
// An highlighted block
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def findBottomLeftValue(self, root: TreeNode) -> int:
queue = [root]
for node in queue:
if node.right:
queue += [node.right]
if node.left:
queue += [node.left]
return node.val
Reference
https://leetcode.com/problems/find-bottom-left-tree-value/discuss/98779/Right-to-Left-BFS-(Python-%2B-Java)