leetcode:Symmetric Tree【Python版】
#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版】的更多相关文章
- [leetcode]Symmetric Tree @ Python
原题地址:https://oj.leetcode.com/problems/symmetric-tree/ 题意:判断二叉树是否为对称的. Given a binary tree, check whe ...
- LeetCode: Symmetric Tree 解题报告
Symmetric Tree Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its ...
- [LeetCode] Symmetric Tree 判断对称树
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- LeetCode——Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- 二叉树系列 - [LeetCode] Symmetric Tree 判断二叉树是否对称,递归和非递归实现
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- [Leetcode] Symmetric tree 对称二叉树
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- Python3解leetcode Symmetric Tree
问题描述: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). ...
- LeetCode() Symmetric Tree
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- leetcode Same Tree python
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...
随机推荐
- JDK并发工具之同步控制
一.synchronized的功能扩展:重入锁(java.util.concurrent.locks.ReentrantLock) 重入锁可以完全替代synchronized关键字.在JDK 5.0的 ...
- 在linux下出现cannot restore segment prot after reloc: Permission denied
应用程序连接oracle的库时会出现如下错误:XXXXX:: error while loading shared libraries: /usr/local/oracle/product/10.2. ...
- ASP.NET MVC 习惯
- OAF 获取页面路径
--模糊查询某个页面 SELECT * FROM JDR_PATHS jp WHERE JP.PATH_NAME LIKE '%XXXX%'; --精确的查找过程 -- DocID --参数通过关于此 ...
- EBS R12 MOAC原理探索 (转)
转载地址 EBS R12 MOAC原理探索
- 阿里云ECS服务器自定义端口无法访问问题记录
记住阿里云ECS服务器有个安全组!!! 购买了阿里云服务器的时候,购买界面那里是可以勾选默认的几个端口是否开启的,服务器默认勾了22端口,使用户能登录服务器. 当我们在服务器里面配置nginx,开启自 ...
- 阿里云ECS安装最新版本Node.js
原文 http://www.w3ctech.com/topic/1610 主题 Node.js操作系统服务器 我的ECS实例是Ubuntu操作系统,直接使用 apt-get install node ...
- 15 int *ptr= (int *)(&a+1)跨了整个数组长度
分析以下程序,输出结果 2,5 #include<stdio.h> int main() { ]={,,,,}; ); printf(),*(ptr-)); ; } 分析: a 代表的是i ...
- js中定时器
周期性定时器:周期性的执行某段代码 window.setInterval() window.clearInterval() 示例: document.it = setInterval(fun ...
- php include,require 主要是向网页中引入文件