Leetcode #404 Sum of Left Leaves
来源:互联网 发布:mac哪些好的软件下载 编辑:程序博客网 时间:2024/05/16 08:33
Description
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.
Explain
判断是否为左子树并且是否不存在子树,都满足则加上这个val
ps:才发现leetcode可以加参数= =
Code
# 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 sumOfLeftLeaves(self, root, isleft=False): """ :type root: TreeNode :rtype: int """ if not root: return 0 if not root.left and not root.right: return root.val if isleft else 0 return self.sumOfLeftLeaves(root.left, True) + self.sumOfLeftLeaves(root.right, False)
0 0
- LeetCode 404 Sum of Left Leaves
- [LeetCode-404]Sum of Left Leaves(java)
- Leetcode 404 Sum of Left Leaves
- LeetCode[404] Sum of Left Leaves
- LeetCode #404: Sum of Left Leaves
- LeetCode 404 Sum of Left Leaves (DFS)
- leetcode 404 Sum of Left Leaves
- LeetCode #404 - Sum of Left Leaves - Easy
- leetcode 404 Sum of Left Leaves C++
- 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
- Sum of Left Leaves ---LeetCode
- Leetcode Sum of Left Leaves
- LEETCODE--Sum of Left Leaves
- 使用Python将Excel中的数据导入到MySQL
- 叠筐
- 大数据IMF传奇行动绝密课程第72课:Spark SQL UDF和UDAF解密与实战
- 注意sonarQube与sonarRunner 的版本匹配(sonarquebe安装)
- Service知识点全解析(一)
- Leetcode #404 Sum of Left Leaves
- 向量几何在游戏编程中的使用2
- 算法复杂度
- 向量几何在游戏编程中的使用3
- JAVA面向对象,重写 重载的区别, 抽象类, 接口,final
- 熄灯问题
- 题目1003:A+B
- HTML 5入门知识(三)
- 向量几何在游戏编程中的使用4