leetcode 404 Sum of Left Leaves
来源:互联网 发布:什么源码值得读知乎 编辑:程序博客网 时间:2024/05/29 16:16
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 = None
class Solution(object):
def sumOfLeftLeaves(self, root):
"""
:type root: TreeNode
:rtype: int
"""
return self.summiao(root)
def summiao(self, root):
if not root:
return 0
sum1=self.summiao(root.left)+self.summiao(root.right)
if root.left!=None:
if root.left.left==None and root.left.right==None:
sum1=sum1+root.left.val
return sum1
- 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
- java定义静态变量时合并多个List
- 第十三周项目3-Dijkstra算法验证
- Spring(一)——总体介绍
- Recyclerview style
- (0010) iOS 开发之UI布局兼容 4s/5/6/7 屏幕解决方案
- leetcode 404 Sum of Left Leaves
- 修改linux的文件权限命令 chmod
- 上楼梯---动态规划问题
- 第十二周项目5--迷宫问题之图深度优先遍历解法
- Spring集成HttpClient实现跨域请求
- spring框架,可以没有spring.xml(即配置<beans>的文件吗?即不使用xml方式配置,而是只使用注解的方式配置
- session 过期设置
- AHUOJ级语言程序设计实验(六)求面积
- 从代理设计模式到Spring AOP