您的位置:首页 > 其它

Same Tree [LeetCode]

2013-10-18 06:14 351 查看
Problem Description: http://oj.leetcode.com/problems/same-tree/

class Solution {
public:
bool isSameTree(TreeNode *p, TreeNode *q) {
// Note: The Solution object is instantiated only once and is reused by each test case.
if(p == NULL && q == NULL)
return true;
if(p == NULL && q != NULL ||
(p != NULL && q == NULL))
return false;
if(p->val != q->val)
return false;
return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: