#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. LeetCode--205--同构字符串

    问题描述: 给定两个字符串 s 和 t,判断它们是否是同构的. 如果 s 中的字符可以被替换得到 t ,那么这两个字符串是同构的. 所有出现的字符都必须用另一个字符替换,同时保留字符的顺序.两个字符不 ...

  2. RabbitMq windows 安装

    参考官方网址: http://www.rabbitmq.com/install-windows-manual.html http://www.rabbitmq.com/install-windows. ...

  3. bfs,dfs区别

    一般来说用DFS解决的问题都可以用BFS来解决. DFS(深搜的同时考虑回溯) bfs=队列,入队列,出队列:dfs=栈,压栈,出栈 bfs是按一层一层来访问的,所以适合有目标求最短路的步数,你想想层 ...

  4. RAC配置(启停库)

    关库顺序 :先关闭数据库 然后关闭节点资源 [root@rac1 ~]# srvctl stop   database  -d 数据库名[root@rac1 ~]# srvctl stop   ins ...

  5. HDOJ1004

    #include<iostream> #include "cstring" using namespace std; int add(char s1[],char s2 ...

  6. ubuntu下没有Language Support

    sudo apt-get installlanguage-selector-gnome

  7. html5-磊哥

    <!doctype html><html lang="en">    <head>        <meta charset=" ...

  8. 如何解决Css属性text-overflow:ellipsis 不起作用(文本溢出显示省略号)

    如何使text-overflow:elipsis起作用? 想要使用css属性text-overflow:elipsis起到作用,样式必须跟overflow:hidden; white-space:no ...

  9. Microsoft Word 2007 向程序发送命令时出现问题解决方法

    最近在打开Word文档时总是出现“向程序发送命令时出现问题”对话框,而且不确定性,关闭重新打开有时没事了有时还不行, 很让人头疼,经过尝试,把问题解决了 1.问题截图如下: 2.解决方法 1)方法一: ...

  10. cas HttpServletRequestWrapperFilter

    HttpServletRequestWrapperFilter 作用其实很简单就是 在HttpServletRequest对象在包装一次,让其支持getUserPrincipal,getRemoteU ...