FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/SameTree.java at master · smrook/leetcode · GitHub
smrook
/
leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
SameTree.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
25 lines (21 loc) · 682 Bytes
Breadcrumbs
leetcode
/
SameTree.java
Copy path
File metadata and controls
executable file
·
25 lines (21 loc) · 682 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
/**
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
Hide Tags Tree Depth-first Search
*/
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public
class
SameTree
{
public
boolean
isSameTree
(
TreeNode
p
,
TreeNode
q
) {
if
(
p
==
q
)
return
true
;
if
(
p
==
null
^
q
==
null
)
return
false
;
return
p
.
val
==
q
.
val
&&
isSameTree
(
p
.
left
,
q
.
left
) &&
isSameTree
(
p
.
right
,
q
.
right
);
}
}
Back
|
FazBrowse Home
|
New Git URL