leetcode404 左叶子之和

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014204761/article/details/83153848
def sumOfLeftLeaves(self, root):
        """
        判断左叶子节点是难点
        """
        res = 0
        if not root:
            return 0
        if  root.left and not root.left.left and not root.left.right :###判断左叶子节点是难点
            res += root.left.val
        return res + self.sumOfLeftLeaves(root.left) + self.sumOfLeftLeaves(root.right)

猜你喜欢

转载自blog.csdn.net/u014204761/article/details/83153848