Skip to content

Commit 8599dd5

Browse files
authoredMay 1, 2017
Same Tree
1 parent 97389ff commit 8599dd5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
 

‎Same Tree.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* struct TreeNode {
4+
* int val;
5+
* TreeNode *left;
6+
* TreeNode *right;
7+
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
8+
* };
9+
*/
10+
class Solution {
11+
public:
12+
bool isSameTree(TreeNode* p, TreeNode* q) {
13+
if(p==NULL && q==NULL)
14+
return true;
15+
if(p==NULL || q==NULL)
16+
return false;
17+
return ((p->val == q->val)&&(isSameTree(p->left,q->left) && isSameTree(p->right,q->right)));
18+
}
19+
};

0 commit comments

Comments
 (0)
Please sign in to comment.