leetcode_c++:树: Symmetric Tree(101)
2016-08-24 17:31
531 查看
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree [1,2,2,3,4,4,3] is symmetric:
But the following [1,2,2,null,3,null,3] is not:
For example, this binary tree [1,2,2,3,4,4,3] is symmetric:
1 / \ 2 2 / \ / \ 3 4 4 3
But the following [1,2,2,null,3,null,3] is not:
1 / \ 2 2 \ \ 3 3
class Solution { private: bool isSymmetric(TreeNode *p, TreeNode *q) { if (p == NULL) return q == NULL; if (q == NULL) return p == NULL; if (p->val != q->val) return false; return isSymmetric(p->left, q->right) && isSymmetric(p->right, q->left); } public: bool isSymmetric(TreeNode *root) { if (root == NULL) return true; return isSymmetric(root->left, root->right); } };
相关文章推荐
- [leetcode-101]Symmetric Tree(c++)
- 【leetcode c++】101 Symmetric Tree
- 【LeetCode-101】 Symmetric Tree(C++)
- LeetCode_101 Symmetric Tree
- LeetCode --- 101. Symmetric Tree
- [LeetCode]101 Symmetric Tree
- [LeetCode#101]Symmetric Tree
- Leetcode 笔记 101 - Symmetric Tree
- leetcode 101 Symmetric Tree
- leetcode_101_Symmetric Tree
- leetcode-101 Symmetric Tree
- Java for LeetCode 101 Symmetric Tree
- leetcode_question_101 Symmetric Tree
- Leetcode[101]-Symmetric Tree
- leetcode[101]:Symmetric Tree
- [Leetcode 101, Easy] Symmetric Tree
- LeetCode: Symmetric Tree [101]
- LeetCode 101 Symmetric Tree
- Leetcode#101 Symmetric Tree
- leetcode_101题——Symmetric Tree (树tree,递归,还有迭代没想出来)