mycode   92.44%

# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None class Solution(object):
def isSymmetric(self, root):
"""
:type root: TreeNode
:rtype: bool
"""
def deal(root,level):
if not root:
self.res[level].append(None)
return 0
self.res[level].append(root.val)
deal(root.left,level+1)
deal(root.right,level+1) from collections import defaultdict
self.res = defaultdict(list) #传入int()函数来初始化
deal(root,0)
for level,item in self.res.items():
if not item == item[::-1]:
return False
return True

参考

# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None class Solution(object):
def isSymmetric(self, root):
"""
:type root: TreeNode
:rtype: bool
""" def traver(left,right):
if not left and not right:
return True
if not left or not right:
return False return (left.val == right.val) and traver(left.left,right.right) and traver(left.right,right.left) return traver(root,root)

leetcode-easy-trees-101. Symmetric Tree-YES的更多相关文章

  1. <LeetCode OJ> 101. Symmetric Tree

    101. Symmetric Tree My Submissions Question Total Accepted: 90196 Total Submissions: 273390 Difficul ...

  2. [LeetCode&Python] Problem 101. Symmetric Tree

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

  3. 【leetcode❤python】101. Symmetric Tree

    #-*- coding: UTF-8 -*-# Definition for a binary tree node.# class TreeNode(object):#     def __init_ ...

  4. 【easy】101. Symmetric Tree

    判断一棵二叉树是否对称 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left ...

  5. Leetcode之101. Symmetric Tree Easy

    Leetcode 101. Symmetric Tree Easy Given a binary tree, check whether it is a mirror of itself (ie, s ...

  6. [leetcode] 101. Symmetric Tree 对称树

    题目大意 #!/usr/bin/env python # coding=utf-8 # Date: 2018-08-30 """ https://leetcode.com ...

  7. leetcode 100. Same Tree、101. Symmetric Tree

    100. Same Tree class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL &am ...

  8. Leetcode 笔记 101 - Symmetric Tree

    题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, s ...

  9. 【LeetCode】101. Symmetric Tree (2 solutions)

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

  10. LeetCode之“树”:Symmetric Tree && Same Tree

    Symmetric Tree 题目链接 题目要求: Given a binary tree, check whether it is a mirror of itself (ie, symmetric ...

随机推荐

  1. CentOS7部署ntp服务器

    主机 角色 192.168.48.128 Server 192.168.48.129 Client 192.168.48.130 Client 所有主机安装ntp服务 yum install -y n ...

  2. BeanUtils组件的使用

    BeanUtils能够使我们更方便的进行javabean的赋值操作,它的底层是反射的原理 主要方法有 copyProperties(Object object,String name,String v ...

  3. Docker架构及其三要素

    1.Docker架构 a.Docker客户端和服务端   Docker是客户-服务器(C/S)架构的程序.Docker客户端只需向Docker服务器或守护进程发出请求,服务器或守护进程将完成所有工作并 ...

  4. MySQL查询一张表有多少个字段

    SQL如下 select count(*) from information_schema.COLUMNS where TABLE_SCHEMA='数据库名' and table_name='表名'

  5. DockerScan:Docker安全分析&测试工具

    DockerScan:Docker安全分析&测试工具 今天给大家介绍的是一款名叫DockerScan的工具,我们可以用它来对Docker进行安全分析或者安全测试. 项目主页 http://gi ...

  6. 学习Linux让我进入了知名企业 原

    说起我学习Linux的原因是多方面的,大学时我学的是物理学师范专业,有部分计算机课程,但我觉得这些课程没什么实际作用,我自己对计算机比较感兴趣,我利用业余时间学习了很多计算机技术.在大学期间我参加了很 ...

  7. 最长回文子串(动规,中心扩散法,Manacher算法)

    题目 leetcode:5. Longest Palindromic Substring 解法 动态规划 时间复杂度\(O(n^2)\),空间复杂度\(O(n^2)\) 基本解法直接看代码 class ...

  8. java将一数组乱序排列

    JAVA的Collections类中shuffle方法模拟了“洗牌”动作可以对list列表进行随机排序.如果一定要自己写,算法也很简单:假设数组array长度为n.用标准随机函数rand(n)生成[0 ...

  9. 区块链——java实现

    简述 本文主要的内容试一次关于区块链的作业,本次作业中有很多地方和实际的区块链不符合,比如hash,本文实现的区块链只是用了区块本身的hash并没去区分,头部和数据部分.仅供参考学习. 介绍 内容有点 ...

  10. antd design vue 设置 v-decorator 的初始值

    v-decorator="['openType', { initialValue:'1' }]" 效果: