forked from xiaoyu2er/leetcode-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zongyanqi
committed
Mar 19, 2017
1 parent
984e54f
commit d756fe9
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Definition for a binary tree node. | ||
* function TreeNode(val) { | ||
* this.val = val; | ||
* this.left = this.right = null; | ||
* } | ||
*/ | ||
/** | ||
* @param {TreeNode} p | ||
* @param {TreeNode} q | ||
* @return {boolean} | ||
*/ | ||
var isSameTree = function (p, q) { | ||
|
||
if (!p && !q) return true; | ||
if (!p || !q) return false; | ||
if (p.val !== q.val) return false; | ||
|
||
return isSameTree(p.left, q.left) && isSameTree(p.right, q.right); | ||
|
||
}; | ||
|
||
|