/**
* 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 {
public:
bool isSymmetric(TreeNode* root) {
if(!root)
return true;
queue<TreeNode*> q;
q.push(root->left);
q.push(root->right);
while(!q.empty()){
TreeNode* lt=q.front();
q.pop();
TreeNode* rt=q.front();
q.pop();
if(!rt&&!lt) continue;
if(!rt||!lt) return false;
if(lt->val!=rt->val) return false;
q.push(lt->left);
q.push(rt->right);
q.push(lt->right);
q.push(rt->left);
}
return true;
}
bool isSymmetricHelper(TreeNode* l,TreeNode* r){
if(!r&&!l) return true;
if((!r&&l)||(!l&&r)||(r->val!=l->val)) return false;
return isSymmetricHelper(l->left,r->right)&&isSymmetricHelper(l->right,r->left); }
};

  

LeetCode() Symmetric Tree的更多相关文章

  1. LeetCode: Symmetric Tree 解题报告

    Symmetric Tree Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its ...

  2. [LeetCode] Symmetric Tree 判断对称树

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

  3. [leetcode]Symmetric Tree @ Python

    原题地址:https://oj.leetcode.com/problems/symmetric-tree/ 题意:判断二叉树是否为对称的. Given a binary tree, check whe ...

  4. LeetCode——Symmetric Tree

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

  5. 二叉树系列 - [LeetCode] Symmetric Tree 判断二叉树是否对称,递归和非递归实现

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

  6. [Leetcode] Symmetric tree 对称二叉树

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

  7. Python3解leetcode Symmetric Tree

    问题描述: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). ...

  8. leetcode:Symmetric Tree【Python版】

    #error caused by:#1:{} 没有考虑None输入#2:{1,2,2} 没有控制h和t#3:{4,-57,-57,#,67,67,#,#,-97,-97} 没有考虑负号,将s从str变 ...

  9. 【LeetCode】Symmetric Tree 推断一棵树是否是镜像的

    题目:Symmetric Tree <span style="font-size:18px;"><span style="font-size:18px; ...

随机推荐

  1. 学习asp.net比较完整的流程[转]

    如果你已经有较多的面向对象开发经验,跳过以下这两步: 第一步 掌握一门.NET面向对象语言,C#或VB.NET 我强烈反对在没系统学过一门面向对象(OO)语言的前提下去学ASP.NET. ASP.NE ...

  2. [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys

    错误原因在于出现相同内容. 原写为: <li ng-repeat="log in logs" scroll-down> {{log}}</li> 改写为: ...

  3. 使用CSS3各个属性实现小人的动画

    使用CSS3各个属性实现带有音乐小人的动画,完全不使用JS代码: 注:chrome浏览器效果最佳,最终效果静态图: HTML代码如下: <!DOCTYPE html> <html&g ...

  4. Large Margin DAGs for Multiclass Classification

    Abstract We present a new learning architecture: the Decision Directed Acyclic Graph (DDAG), which i ...

  5. Fragment的使用(一)

    本篇博客主要讲的是如何使用Fragment. 使用Fragment的步骤类似于自定义View的步骤: 定义Fragment的布局文件 实现扩展Fragment的子类 在扩展子类的onCreateVie ...

  6. DataTable的子查询--DataTable.Select()

    由于需要,在sql查询获得结果集之后,又需要对该结果再进行筛选一次,若重新从sql中查询会浪费资源,因此特地去查阅了一些资料,学会了用DataTable进行子查询. 在.Net Framework 2 ...

  7. jdk安装及环境变量配置

    JDK是 Java 语言的软件开发工具包,主要用于移动设备.嵌入式设备上的java应用程序.JDK是整个java开发的核心,它包含了JAVA的运行环境,JAVA工具和JAVA基础的类库. jdk下载地 ...

  8. IOS百度地图获取所在的城市名称

    笔者的app要实现定位所在省和城市名称,借此总结巩固一下! @interface VenueListVC : BasePageTableViewVC<BMKLocationServiceDele ...

  9. iOS-打电话、发短信、发邮件、打开浏览器

    - (IBAction)showAlert:(UIButton *)sender { NSString *phoneNumber=@"18500138888"; NSString ...

  10. C++复数类对除法运算符 / 的重载

    C8-1 复数加减乘除 (100.0/100.0 points) 题目描述 求两个复数的加减乘除. 输入描述 第一行两个double类型数,表示第一个复数的实部虚部 第二行两个double类型数,表示 ...