#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. Assert.IsNotNull 方法(判断对象不为NULL)

    Assert.IsNotNull 方法 Visual Studio 2012   其他版本 Visual Studio 2010 Visual Studio 2008 Visual Studio 20 ...

  2. English trip -- VC(情景课)5 Around Town

     Around Town  城市周围 Talk about the picture 看图说话 sentences Where are you? I'm in the Meten classroom. ...

  3. 54 Django 模型层(1) 单表查询

    单表操作: 一 项目的操作顺序: 1 在model.py文件中创建表结构 class Book(models.Model): id=models.AutoField(primary_key=True) ...

  4. Tips for Sync Vimtex and PDF

    vimtex synctex: \lv. skim synctex: to display the TeX source line corresponding to a point in the PD ...

  5. python-day39--数据库

    1.什么是数据:描述事物的特征,提取对自己有用的信息  称之为数据 2..什么是数据库: 数据库即存放数据的仓库,只不过这个仓库是在计算机存储设备上,而且数据是按一定的格式存放的 为什么要用数据库: ...

  6. python-day8-元组的内置方法

    #为何要有元组,存放多个值,元组不可变,更多的是用来做查询# t=(1,[1,3],'sss',(1,2)) #t=tuple((1,[1,3],'sss',(1,2)))# print(type(t ...

  7. Windows系统下修改Erlang默认路径

    新建.erlang文件: io:format("consulting .erlang in ~p~n",[element(2, file:get_cwd())]). c:cd(&q ...

  8. OC NSArray数组排序

    一.一般排序 // 排序 NSArray *arr = @["]; NSArray *newarr = [arr sortedArrayUsingSelector:@selector(com ...

  9. SQL触发器实例(下)

    基本语法: Create Trigger [TriggerName] ON [TableName] FOR [Insert][,Delete][,Update] AS --触发器要执行的操作语句. G ...

  10. 51nod算法马拉松28-c

    题解: 按照每一个要求,分类讨论,讨论压下去了多少 代码: #include<bits/stdc++.h> using namespace std; ,N=; int n,A,B,C,an ...