Problem Description: http://oj.leetcode.com/problems/same-tree/

 1 class Solution {
 2 public:
 3     bool isSameTree(TreeNode *p, TreeNode *q) {
 4         // Note: The Solution object is instantiated only once and is reused by each test case.
 5         if(p == NULL && q == NULL)
 6             return true;
 7         if(p == NULL && q != NULL ||
 8             (p != NULL && q == NULL))
 9             return false;
10         if(p->val != q->val)
11             return false;
12         return isSameTree(p->left, q->left) && isSameTree(p->right, q->right); 
13     }
14 };

 

相关文章:

  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2021-09-13
猜你喜欢
  • 2021-10-11
  • 2021-11-10
  • 2021-11-01
  • 2021-09-07
  • 2022-01-04
相关资源
相似解决方案