Algorithms—112.Path Sum
来源:互联网 发布:抓取股票数据 网站 编辑:程序博客网 时间:2024/06/06 09:04
思路:easy的题目,不用动态规划也过了
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public boolean hasPathSum(TreeNode root, int sum) { if (root==null) { return false;} boolean flag1=false; if (root.val==sum&&root.left==null&&root.right==null) {return true;} if (root.left!=null) {flag1=hasPathSum(root.left, sum-root.val);} if (flag1) {return true;} if (root.right!=null) { return hasPathSum(root.right, sum-root.val);} return false; }}
耗时:352ms
0 0
- Algorithms—112.Path Sum
- Algorithms—113.Path Sum II
- Algorithms-64.Minimum Path Sum
- LeetCode Algorithms 113. Path Sum II 题解
- LeetCode Algorithms 113. Path Sum II
- Algorithms—15.3Sum
- Algorithms—18.4Sum
- Algorithms—39.Combination Sum
- Algorithms—16.3Sum Closest
- 算法设计Week13 LeetCode Algorithms Problem #64 Minimum Path Sum
- 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
- awesome-android-ui
- 一个程序员的成长独白
- const实现机制
- android studio mac 常用快捷键
- 判断字符串不为空定义红
- Algorithms—112.Path Sum
- UIApplication、AppDelegate、委托
- 通过JS+CSS实现简单的遮罩层
- 修改Maven本地仓库和eclipse3.6的Maven本地仓库地址
- cocos2dx3.4mac环境搭建
- dns 添加域名
- 九度OJ 题目1063:整数和
- 24小时制转换为12小时
- 路由配置