#error caused by:
#1:{} 没有考虑None输入
#2:{1,2,2} 没有控制h和t
#3:{4,-57,-57,#,67,67,#,#,-97,-97} 没有考虑负号,将s从str变成list,采用9999代表空数值;

---------------------

逐层进行对称性验证,出现不对称就结束;

 # Definition for a  binary tree node
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None class Solution:
# @param root, a tree node
# @return a boolean
def isSymmetric(self,root):
ret = True
q = []
s = []
if root != None:#注意root为空
q.append(root)
s.append(root.val)
while (len(q) != 0 and ret == True):
h = 0
t = len(s) - 1
while (h < t):
if (s[h] != s[t]):
ret = False
break
h+=1#这里忘记控制h和t了
t-=1
tq = q
s = []
q = []
while (len(tq) != 0 and ret == True):
t = tq.pop(0)#pop默认弹出最后一个值
if t.left != None:
q.append(t.left)
s.append(t.left.val)
else:
s.append(9999)
if t.right != None:
q.append(t.right)
s.append(t.right.val)
else:
s.append(9999)
return ret

leetcode:Symmetric Tree【Python版】的更多相关文章

  1. [leetcode]Symmetric Tree @ Python

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

  2. LeetCode: Symmetric Tree 解题报告

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

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

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

  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

    /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...

  9. leetcode Same Tree python

    # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...

随机推荐

  1. English trip -- VC(情景课)1 A Get ready

    Meet your classmates 见见你的同学 Look at the picture. What do you see? 看图片.你看到了什么? calendar  日历 bookcase ...

  2. Android设计模式之工厂模式

    定义 工厂模式是我们最常用的实例化对象模式了,是用工厂方法代替new操作的一种模式.著名的Jive论坛 ,就大量使用了工厂模式,工厂模式在Java程序系统可以说是随处可见.因为工厂模式就相当于创建实例 ...

  3. dp练习(2)——老鼠的旅行

    1267 老鼠的旅行(来源:codevs) #include "bits/stdc++.h" using namespace std; ][]; ][]; int main() { ...

  4. 用Maven构建Mahout项目

    转载请注明出处:http://blog.fens.me/hadoop-mahout-maven-eclipse/ Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Hadoop, ...

  5. 014PHP文件处理——文件指针控制fseek rewind ftell feof fpassthru

    <?php /** * 文件指针控制fseek rewind ftell feof fpassthru */ //feof()判断文件读取是否超出文件长度 /*$file = fopen('a. ...

  6. js解码编码decodeURI与decodeURIComponent区别

    ###decodeURI与decodeURIComponent区别 1. 概念: URI: Uniform ResourceIdentifiers,通用资源标识符 Global对象的encodeURI ...

  7. python笔记03:使用字符串

    3.1 基本字符串操作: 所有的标准序列操作(索引,分片,乘法,判断成员资格,求长度,取最小值,取最大值)对于字符串同样有效.但是,请记住:字符串都是不可变的 3.2 字符串格式化:精简版 字符串格式 ...

  8. L1-012 计算指数

    真的没骗你,这道才是简单题 —— 对任意给定的不超过 10 的正整数 n,要求你输出 2​n​​.不难吧? 输入格式: 输入在一行中给出一个不超过 10 的正整数 n. 输出格式: 在一行中按照格式  ...

  9. mongodb添加延时节点

    1.      简介 延时节点是主节点过去某个时间点的“数据快照”,通常用来做数据备份,如果主节点有误操作而删除了数据,可以通过延时节点来恢复数据.例如,当前时间是10:00,并且延时节点设置1个小时 ...

  10. get_class

    <?phpclass foo {    function foo()    {    // implements some logic    }    function name()    {  ...