【leetcode】404. Sum of Left Leaves【E】
来源:互联网 发布:985贴吧 知乎 编辑:程序博客网 时间:2024/05/16 12:30
Find the sum of all left leaves in a given binary tree.
Example:
3 / \ 9 20 / \ 15 7There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24.
Subscribe to see which companies asked this question
这是一道找不到的题,哈哈
就是对每个节点,判断其是不是左节点+叶子节点
递归进行
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution(object): def isLeaf(self,root): if root.left == None and root.right == None: return True def sumOfLeftLeaves(self, root): if root == None: return 0 res = 0 #print root.val if root.left and self.isLeaf(root.left): res += root.left.val res += self.sumOfLeftLeaves(root.left) + self.sumOfLeftLeaves(root.right) return res """ :type root: TreeNode :rtype: int """
0 0
- 【leetcode】404. Sum of Left Leaves【E】
- LeetCode笔记:404. Sum of Left Leaves
- LeetCode—404. Sum of Left Leaves
- [LeetCode]404. Sum of Left Leaves
- Leetcode 404. Sum of Left Leaves
- LeetCode 404. Sum of Left Leaves
- 404. Sum of Left Leaves - leetcode
- [LeetCode]--404. Sum of Left Leaves
- LeetCode 404. Sum of Left Leaves
- [leetcode]404. Sum of Left Leaves
- LeetCode-404. Sum of Left Leaves
- LeetCode 404. Sum of Left Leaves
- LeetCode 404. Sum of Left Leaves
- leetcode 404. Sum of Left Leaves
- leetcode(88).404. Sum of Left Leaves
- 【LeetCode】 404. Sum of Left Leaves
- leetcode 404. Sum of Left Leaves
- [Leetcode]404. Sum of Left Leaves
- 容器技术当前的不足和发展方向
- 原生js解决微信在iOS上无法修改title的问题
- 解决_java.sql.SQLException: Your password has expired.
- 什么是P问题、NP问题和NPC问题
- C++ 面向对象程序设计上机练习四(变量引用)
- 【leetcode】404. Sum of Left Leaves【E】
- Odoo ORM API (二)- Creating Models、Compatibility between new API and old API
- OpenGL系列教程之十一:OpenGL网格化
- android RelativeLayout 居中
- mysql 远程连接--Host'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server
- 巴蜀 2904 MMT数
- ThinkPHP中坑爹的关联模型
- MFC最小化到托盘
- 如何高效的使用STL