-
Notifications
You must be signed in to change notification settings - Fork 0
/
leetcode100.cpp
42 lines (39 loc) · 1.06 KB
/
leetcode100.cpp
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
31
32
33
34
35
36
37
38
39
40
41
/*************************************************************************
> File Name: leetcode100.cpp
> Author:
> Mail:
> Created Time: Mon 12 Sep 2016 06:24:35 PM PDT
************************************************************************/
#include<iostream>
using namespace std;
struct TreeNode {
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};
bool isSameTree(TreeNode* p, TreeNode* q) {
if(p == NULL && q == NULL)
{
return true;
}
else if(p == NULL || q == NULL)
{
return false;
}
return p->val == q->val && isSameTree(p->left,q->left) && isSameTree(p->right,q->right);
}
int main()
{
TreeNode* first = new TreeNode(1);
TreeNode* sec = new TreeNode(2);
TreeNode* third = new TreeNode(3);
first->right = sec;
sec->left = third;
TreeNode* fourth = new TreeNode(1);
TreeNode* five = new TreeNode(2);
TreeNode* six = new TreeNode(3);
fourth->right = five;
five->left = six;
cout << isSameTree(first,fourth) << endl;
}