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 };
递归判定
浙公网安备 33010602011771号