leetcode 112 Path Su
来源:互联网 发布:安卓远程桌面软件 编辑:程序博客网 时间:2024/06/05 12:45
题目:点击打开链接
开始我加了条件
if(root->val>sum) return false;这个相当于一个优化,可是出错的地方是可能输入是负数,只对正数有效。错误测试用例是{-2,#,-3},-5
class Solution {public: bool hasPathSum(TreeNode *root, int sum) { if(root==NULL) { return false; } if(root->val==sum&&root->left==NULL&&root->right==NULL) { return true; } return hasPathSum(root->left, sum-root->val)||hasPathSum(root->right, sum-root->val); }};
0 0
- leetcode 112 Path Su
- LeetCode(112)Path Sum
- LeetCode 112 Path Sum
- LeetCode: Path Sum [112]
- LeetCode 112 Path Sum
- [leetcode 112] Path Sum
- leetCode #112 path sum
- [LeetCode 112]Path Sum
- leetcode || 112、Path Sum
- LeetCode 112: Path Sum
- LeetCode 112 Path Sum
- leetcode[112]:Path Sum
- leetcode-112-Path Sum
- Leetcode# 112 Path Sum
- leetcode 112: Path Sum
- LeetCode 112: Path Sum
- [leetcode 112]Path Sum
- LeetCode 112 Path Sum
- ArrayList初步
- DSADADSAD
- Android中JSON数据使用
- C++ Primer学习总结 第15章 面向对象程序设计
- IntelliJ Idea 常用快捷键列表
- leetcode 112 Path Su
- Leetcode Add Two Numbers
- matlab syms subs eval 实例
- error LNK2001: 无法解析的外部符号 _IID_IDirectDraw7
- hdu 3849 By Recognizing These Guys, We Find Social Networks Useful
- 彻底删除Oracle 10g
- SQL Server2008创建约束图解
- Gradle简介
- FAT32、NTFS、EXT