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
posted @ 2019-11-20 15:46  欣姐姐  阅读(93)  评论(0编辑  收藏  举报