Leetcode 101. Symmetric Tree
来源:互联网 发布:有意义的化学式 知乎 编辑:程序博客网 时间:2024/05/16 07:02
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
But the following is not:
1
/ \
2 2
\ \
3 3
/** * 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 isSymmetric(TreeNode *root) { TreeNode *left, *right; if (!root) return true; queue<TreeNode*> q1, q2; q1.push(root->left); q2.push(root->right); while (!q1.empty() && !q2.empty()){ left = q1.front(); q1.pop(); right = q2.front(); q2.pop(); if (NULL == left && NULL == right) continue; if (NULL == left || NULL == right) return false; if (left->val != right->val) return false; q1.push(left->left); q1.push(left->right); q2.push(right->right); q2.push(right->left); } return true; }};
0 0
- 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
- Leetcode 101. Symmetric Tree
- 101. Symmetric Tree LeetCode
- [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
- Using Statement vs Try-Finally
- PowerPoint常见问题及对策
- 顺时针打印矩阵
- dwz系列之一--项目引入dwz
- 数据库高可用架构(MySQL、Oracle、MongoDB、Redis)
- Leetcode 101. Symmetric Tree
- ubuntu乱码问题
- Android实现点击通知栏后,先启动应用再打开目标Activity
- Tomcat中部署web应用 ---- Dubbo服务消费者Web应用war包的部署
- JEECG快速深度学习—入门到精通实战
- while(pid1 = fork()== -1);直接分号,循环语句为空
- file:/D:/Tomcat%206.0/webapps/Struts2UserLogin/WEB-INF/classes/struts.xml:3:8
- Python3 的异常处理
- centos6.5 企业知识管理与协同软件 Confluence5.1 最新版的安装&破解&汉化