博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Path Sum
阅读量:7040 次
发布时间:2019-06-28

本文共 916 字,大约阅读时间需要 3 分钟。

hot3.png

Path Sum/** * Definition for binary tree * 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;          }          if(root.left == null && root.right == null && root.val == sum){              return true;          }          if(root.left != null && root.right == null){              return hasPathSum(root.left , sum - root.val);          }          if(root.right != null && root.left == null){              return hasPathSum(root.right , sum - root.val);          }          if(root.left != null && root.right != null){              return hasPathSum(root.left , sum - root.val) || hasPathSum(root.right , sum - root.val);          }          return false;    }}

转载于:https://my.oschina.net/LosersAFC/blog/226649

你可能感兴趣的文章
mongoose学习文档
查看>>
关于接口
查看>>
Mixin Messenger 源码解读 1 — — WCDB Swift
查看>>
PgwSlideshow-基于Jquery的图片轮播插件
查看>>
cookie、session、sessionid 与jsessionid
查看>>
一行 Shell 通过 Nginx access 日志实时统计单台机器QPS
查看>>
改变button上title和图片的位置
查看>>
C# 组件模组引用第三方组件问题
查看>>
WebForm 内置对象2
查看>>
使用Web.Config Transformation配置灵活的配置文件
查看>>
一个简单的sel server 函数的自定义
查看>>
linux文件权限详解
查看>>
必应词典桌面版 --- 基于大学生用户群体的软件评测与分析(与有道词典对比版 1功能篇)...
查看>>
转贴:Linq的Distinct太不给力了
查看>>
Duwamish深入剖析-结构篇
查看>>
ASP.NET Sprite and Image Optimization Framework 小demo
查看>>
LeetCode 258-Add Digits
查看>>
例题9-12 UVa12186 Another Crisis(树型DP)
查看>>
hdu 杭电 2216 Game III
查看>>
post-image.sh hacking
查看>>