FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/code/lc112.java at master · mJackie/leetcode · GitHub
mJackie
/
leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
135
Star
405
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
code
/
lc112.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (30 loc) · 889 Bytes
Breadcrumbs
leetcode
/
code
/
lc112.java
Copy path
File metadata and controls
30 lines (30 loc) · 889 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package
code
;
/*
* 112. Path Sum
* 题意:是否存在跟到叶子节点的和为sum
* 难度:Easy
* 分类:
* 思路:
* Tips:lc112, lc113, lc437, lc129, lc124, lc337
* 总结一下 lc112 找跟到叶子和为sum的路径是否存在
* lc113 把lc112的路径找出来
* lc437 是任意一条向下走的路径
* lc129 计算所有的和
* lc124 任意一条路径
* lc337 树的dp
*/
public
class
lc112
{
public
class
TreeNode
{
int
val
;
TreeNode
left
;
TreeNode
right
;
TreeNode
(
int
x
) {
val
=
x
;
}
}
public
boolean
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
);
}
}
Back
|
FazBrowse Home
|
New Git URL