题目描述
给定一个二叉树,在树的最后一行找到最左边的值。
思路
代码
class Solution:
def findBottomLeftValue(self,root:TreeNode) -> int:
if not root:
return None
if not root.left and not root.right:
return root.val
if self.height(root.left) >= self.height(root.right):
return self.findBottomLeftValue(root.left)
return self.findBottomLeftValue(root.right)
def height(self,root):
if not root:
return 0
return 1 + max(self.height(root.left),self.height(root.right))