2017.11.3 LeetCode
来源:互联网 发布:java算法书籍推荐 编辑:程序博客网 时间:2024/06/03 18:51
101. Symmetric Tree
Description
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:
题意: 判断一个树是否是对称的
分析: 直接dfs搜即可,注意的就是left 对应 right ,right 对应 left
参考函数
class Solution {public: bool tag = true; void dfs(TreeNode* root_l,TreeNode* root_r) { if(!root_l && !root_r) return; if(!root_l || !root_r) { tag = false;return; } if(root_l->val != root_r->val) { tag = false;return; } dfs(root_l->left,root_r->right); dfs(root_l->right,root_r->left); } bool isSymmetric(TreeNode* root) { if(!root) return tag; dfs(root->left,root->right); return tag; }};
阅读全文
0 0
- 2017.11.3 LeetCode
- leetcode 3
- LeetCode(3)
- LeetCode--3
- LeetCode(3)
- LeetCode-3*
- leetcode(3)
- LeetCode(3)
- leetcode 3
- LeetCode(3)
- leetcode note--leetcode 16 3Sum Closest
- 2017.11.1 LeetCode
- 2017.11.2 LeetCode
- 2017.11.4 LeetCode
- 2017.11.5 LeetCode
- 2017.11.9 LeetCode
- 2017.11.14 LeetCode
- 2017.11.21 LeetCode
- 全局变量错误
- MySQL存储过程题目
- js中的键盘事件:onkeydown、onkeypress、onkeyup
- Hash表c++实现
- Android开发页面去掉顶部标题栏
- 2017.11.3 LeetCode
- C语言入门——数字特征值
- hibernate查询list结果集结果都是一样
- s3c2440 ARM9 裸机驱动第一篇-GPIO驱动(C)
- [2017纪中11-3]机房比教室好多了 博弈+树型DP
- JAVA内存模型
- cipher
- Ubuntu安装Tomcat
- hiERROR: Value '0000-00-00' can not be represented as java.sql.Timestamp