112. Path Sum
来源:互联网 发布:如何评价secrets 知乎 编辑:程序博客网 时间:2024/06/12 18:13
原文题目:
112. Path Sum
读题:
二叉树中是否存在给定和为给定数的路径,递归实现最简单
# 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 hasPathSum(self, root, sum): """ :type root: TreeNode :type sum: int :rtype: bool """ if not root: return False if not root.left and not root.right and sum == root.val: return True return self.hasPathSum(root.left, sum - root.val) or self.hasPathSum(root.right, sum - root.val)
阅读全文
0 0
- 112. Path Sum && 113. Path Sum II
- 112. Path Sum&113. Path Sum II
- 112.Path Sum
- LeetCode 112. Path Sum
- [LeetCode]112.Path Sum
- 【LeetCode】112.Path Sum
- [Leetcode] 112. Path Sum
- [leetcode] 112.Path Sum
- 112.Path Sum
- 112. Path Sum
- 112. Path Sum
- 112. Path Sum
- 112. Path Sum
- 112. Path Sum LeetCode
- 112. Path Sum
- 112. Path Sum
- 112. Path Sum
- 112. Path Sum
- Python笔记——python简介、特点、安装及helloworld
- Java内存模型和JVM内存管理
- cuda编程---cuda硬件信息与错误处置
- 01
- POJ-2774-后缀数组
- 112. Path Sum
- arcgis for js 船舶 拉旗
- 我们是如何做数据库运维和优化
- 想要购买二手域名先进行的四项检查
- Python笔记——类定义
- 设计模式之——观察者设计模式
- c语言_s错误解决
- spring管理属性配置文件properties——使用PropertiesFactoryBean
- HDOJ1425 sort(最简单的hash)