leetcode——404. 左叶子之和

class Solution:
    def sumOfLeftLeaves(self, root: TreeNode) -> int:
        if not root:
            return 0
        if root and root.left and not root.left.left and not root.left.right:
            return root.left.val+self.sumOfLeftLeaves(root.right)
        return self.sumOfLeftLeaves(root.left) + self.sumOfLeftLeaves(root.right)
执行用时 :44 ms, 在所有 python3 提交中击败了79.85%的用户
内存消耗 :14.2 MB, 在所有 python3 提交中击败了5.22%的用户
 
 
——2019.11.20

猜你喜欢

转载自www.cnblogs.com/taoyuxin/p/11898256.html