Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7885414

Browse files
100. Same Tree
1 parent 57bfaa3 commit 7885414

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎src/100. Same Tree.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* 100. Same Tree
3+
* https://leetcode.com/problems/same-tree/
4+
* Definition for a binary tree node.
5+
* function TreeNode(val) {
6+
* this.val = val;
7+
* this.left = this.right = null;
8+
* }
9+
*/
10+
/**
11+
* @param {TreeNode} p
12+
* @param {TreeNode} q
13+
* @return {boolean}
14+
*/
15+
var isSameTree = function (p, q) {
16+
if (!p && !q) {
17+
return true;
18+
}
19+
if (!p || !q) {
20+
return false;
21+
}
22+
return p.val === q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
23+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /