Given a binary tree, find the leftmost value in the last row of the tree.
Example 1:
Input: 2 / 1 3 Output: 1
Example 2:
Input: 1 / 2 3 / / 4 5 6 / 7 Output: 7
Note: You may assume the tree (i.e., the given root node) is not NULL.
求二叉树左下方节点的值,使用广度优先遍历,每遍历一层刷新result值
class Solution(object):
def findBottomLeftValue(self, root):
"""
:type root: TreeNode
:rtype: int
"""
left = 0
if(not root):
return left
result = []
queue = [root]
while(queue):
count = len(queue)
for i in range(0, count):
node = queue.pop(0)
if i == 0:
left = node.val
if(node.left):
queue.append(node.left)
if(node.right):
queue.append(node.right)
return left