Same Tree [LeetCode]
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 };