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. 【From StackOverFlow】--set-upstream 和--set-upstream-to=以及--track的区别

    本文引自StackOverFlow http://stackoverflow.com/questions/26090689/git-set-upstream-to-vr-track

  2. 配置maven的国内镜像

    pom.xml文件出现错误标记,一般是相关的maven资源没有下载完整. 1,配置maven的国内镜像,保证能够顺利下载maven中配置的资源. 在maven的配置文件  settings.xml  ...

  3. 10、LNMP架构

    1LNMP架构概述 1.1.什么是LNMP  LNMP 是一套技术的组合,L = Linux,N = Nginx,M~ = MySQL,P~ = PHP 1.2.LNMP架构是如何工作的 首先Ngin ...

  4. MobileNet系列

    最近一段时间,重新研读了谷歌的mobilenet系列,对该系列有新的认识. 1.MobileNet V1 这篇论文是谷歌在2017年提出了,专注于移动端或者嵌入式设备中的轻量级CNN网络.该论文最大的 ...

  5. 1.K近邻算法

    (一)K近邻算法基础 K近邻(KNN)算法优点 思想极度简单 应用数学知识少(近乎为0) 效果好 可以解释机器学习算法使用过程中的很多细节问题 更完整的刻画机器学习应用的流程 图解K近邻算法 上图是以 ...

  6. CRM项目讲解和django知识点回顾

    今天想把之前写的CRM项目梳理下,顺便回顾一下djiango的部分重要知识. 1.登录页面(包含简单验证码) 首先来看下CRM的登录页面,样式啥的不重要,大家可以去jquery ui的网站上或者其他地 ...

  7. Circle HDU - 6550 (数学)

    在半径为 1 的圆上有 n 个点,它们也是圆的 n 等分点,将每个相邻的 n 等分点相连,组成了一个正 n边形,现在你可以在圆上再增加一个点,使得新的 n + 1 边形的面积最大,请输出最大面积. I ...

  8. 10.Go-goroutine,waitgroup,互斥锁,channel和select

    10.1.goroutine goroutine的使用 //Learn_Go/main.go package main import ( "fmt" "time" ...

  9. 解决java编译错误:编码 GBK 的不可映射字符 (0x8C)

    1. 问题概述: 程序很简单,打印一行字:你好,世界 (使用的工具是:win10自带的记事本.java的jdk:java development kit) 但是在打开终端进行编译时,报出了一个错误:编 ...

  10. C#制作的屏幕取色器

    1 using System;  2 using System.Collections.Generic;  3 using System.ComponentModel;  4 using System ...