404. Sum of Left Leaves
来源:互联网 发布:魏晨全球歌迷会淘宝网 编辑:程序博客网 时间:2024/06/16 18:03
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.
# 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): """ :type root: TreeNode :rtype: int """ sum=0 if(root): l,r=root.left,root.right if l and (l.left or l.right) is None: sum+=l.val sum=self.sumOfLeftLeaves(l)+sum+self.sumOfLeftLeaves(r) return sum
0 0
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves*
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- 404. Sum of Left Leaves
- ArrayList、Vector、HashMap、HashSet的默认初始容量、加载因子、扩容增量
- 二叉树的前/中/后序遍历算法(非递归)
- 利用SQOOP将数据从数据库导入到HDFS
- swift系列:新手村第一周
- 【HTML】No.5 HTML属性
- 404. Sum of Left Leaves
- Rust: 从csv文件转成kbar的尝试:速度,还有Julia和激情
- servlet 路径
- java(三)
- Mybatis源码拜读
- Android Studio 优秀插件汇总
- Java sdut acm 1140 面向对象程序设计上机练习一(函数重载)
- Git的安装与配置
- springmvc常用标签库