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 static int wing=[]()
11 {
12     std::ios::sync_with_stdio(false);
13     cin.tie(NULL);
14     return 0;
15 }();
16 
17 class Solution 
18 {
19 public:
20     bool isSameTree(TreeNode* p, TreeNode* q) 
21     {
22         if(p==NULL||q==NULL)
23             return p==q;
24         if(p->val!=q->val)
25             return false;
26         return isSameTree(p->left,q->left)&&isSameTree(p->right,q->right);
27     }
28 };

递归判定

posted on 2018-04-17 14:30  高数考了59  阅读(107)  评论(0)    收藏  举报