leetcode-Symmetric Tree
来源:互联网 发布:idc联想数据 编辑:程序博客网 时间:2024/06/12 00:10
Difficulty: Easy
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree is symmetric:
1 / \ 2 2 / \ / \3 4 4 3
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution { bool helper(TreeNode *root1,TreeNode *root2){ if(!root1&&!root2) return true ; if(!root1||!root2) return false; if(root1->val==root2->val) return helper(root1->left,root2->right)&&helper(root1->right,root2->left); return false; } public: bool isSymmetric(TreeNode* root) { if(!root) return true; return helper(root->left,root->right); }};
0 0
- Leetcode - Tree - Symmetric Tree
- Leetcode - Tree - Symmetric Tree
- LeetCode[Tree]: Symmetric Tree
- [leetcode][tree] Symmetric Tree
- LeetCode: Symmetric Tree
- [Leetcode] Symmetric Tree
- LeetCode : Symmetric Tree
- leetcode 13:symmetric tree
- [LeetCode] Symmetric Tree - Recursively
- [LeetCode] Symmetric Tree - Iteratively
- [LeetCode] Symmetric Tree
- [LeetCode]Symmetric Tree
- Leetcode:Symmetric Tree
- [Leetcode]Symmetric Tree
- Leetcode: Symmetric Tree
- [leetcode]Symmetric Tree
- LeetCode-Symmetric Tree
- [leetcode] Symmetric Tree
- [ahk]改变Excel的sheet标签颜色
- UI - UISwitchAndUIActivityIndicatorView
- MySQL 源码编译安装报错 Googlemock was not found
- 使用Cocos2d-lua开发植物大战僵尸09-实现添加植物
- Heap
- leetcode-Symmetric Tree
- lib与dll文件的区别与联系
- Range Sum Query - Immutable
- 深入浅出Android Support Annotation(什么是android.support.annotation.NonNull的拓展)【转】
- Hibernate 面试总结
- Android快速SDK(10)地址库Location【傻瓜模式】
- sicily 10625 TRENER
- ubuntu下把微信的amr音频格式转换为 mp3格式
- ZOJ 1563 Pearls(一个物品和他之前的组合情况)