LeetCode--same-tree
2018-01-08 12:52
405 查看
题目描述
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: bool isSameTree(TreeNode *p, TreeNode *q) { if(p==NULL && q==NULL) return true; else if(p==NULL || q==NULL) return false; else if(p->val != q->val)return false; return isSameTree(p->left,q->left) && isSameTree(p->right,q->right); } };
相关文章推荐
- leetcode -- Same Tree -- 简单重点
- Same Tree [LeetCode]
- Leetcode在线编程same-tree
- LeetCode Same Tree 决定是否是相同的树
- [LeetCode] [Same Tree 2012-09-03 ]
- LeetCode Same Tree OJ 算法 刷题
- Leetcode-100: Same Tree
- leetcode — same-tree
- leetcode100题< Same Tree >(java)
- leetcode笔记:Same Tree
- [leetcode.com]算法题目 - Same Tree
- leetcode Same Tree
- [LeetCode] Same Tree
- leetcode — same-tree
- leetcode:100 Same Tree-每日编程第六题
- leetcode100 Same Tree java
- [Leetcode]-Same Tree
- Leetcode 100 : same Tree
- Leetcode: Same Tree
- LeetCode---Same Tree