leetcood学习笔记-226- 翻转二叉树
题目描述:
第一次提交:
class Solution(object):
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
if not root:
return None
temp = root.left
root.left = root.right
root.right = temp# root.left,root.right = root.right,root.left
self.invertTree(root.left)
self.invertTree(root.right)
return root
可缩减代码:
class Solution(object):
def invertTree(self, root):
"""
:type root: TreeNode
:rtype: TreeNode
"""
if not root :
return root
else:
root.left,root.right=self.invertTree(root.right),self.invertTree(root.left)
return root
leetcood学习笔记-226- 翻转二叉树的更多相关文章
- leetcood学习笔记-965-单值二叉树
题目描述; 第一次提交; class Solution: def isUnivalTree(self, root: TreeNode) -> bool: if root == None: ret ...
- leetcood学习笔记-110-平衡二叉树
---恢复内容开始--- 题目描述: 方法一: class Solution(object): def isBalanced(self, root): """ :type ...
- leetcood学习笔记-101-对称二叉树
题目描述: 方法一:递归: class Solution: def isSymmetric(self, root: TreeNode) -> bool: if not root: return ...
- Java实现 LeetCode 226 翻转二叉树
226. 翻转二叉树 翻转一棵二叉树. 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 备注: 这个问题是受到 Max ...
- 力扣(LeetCode)226. 翻转二叉树
翻转一棵二叉树. 示例: 思想 递归 java版 /** * Definition for a binary tree node. * public class TreeNode { * int va ...
- Leetcode题目226.翻转二叉树(简单)
题目描述: 翻转一颗二叉树 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 思路分析: 1)递归,不断交换左右子树,直到 ...
- leetcood学习笔记-54-螺旋矩阵
题目描述: 第一次提交: class Solution: def spiralOrder(self, matrix: List[List[int]]) -> List[int]: j,x = 0 ...
- 【LeetCode】226. 翻转二叉树
题目 翻转一棵二叉树. 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 本题同[剑指Offer]面试题27. 二叉树的镜 ...
- leetcood学习笔记-20
python字符串与列表的相互转换 学习内容: 1.字符串转列表 2.列表转字符串 1. 字符串转列表 str1 = "hi hello world" print(str1.s ...
随机推荐
- Shell内置命令let
- TCP协议中的三次握手和四次挥手(图解)(转)
转自:http://blog.csdn.net/whuslei/article/details/6667471 建立TCP需要三次握手才能建立,而断开连接则需要四次握手.整个过程如下图所示: 先来看看 ...
- java中的继承、重载和覆盖是什么意思
继承(英语:inheritance)是面向对象软件技术当中的一个概念.如果一个类别A“继承自”另一个类别B,就把这个A称为“B的子类别”,而把B称为“A的父类别”也可以称“B是A的超类”.继承可以使得 ...
- 通信矩阵转DBC
DBC的制作对于一些人来时比较陌生,熟悉的人做他感觉浪费时间(像我这样的),于是自己用PYTHON写了一个脚本,还挺好用的,只需要填写表格就好了,省出来大部分的时间. 分享下思路, 来看下DBC的文本 ...
- 将中国标准时间)转化为yyyy-MM-dd
有两种方法: 1. ]); ) + '-' + d.getDate() + ' ' + d.getHours() + ':' + d.getMinutes() + ':' + d.getSeconds ...
- C# 调用c++数据类型对应
C#调用 非托管C++ dll 传入Stringbuilder.ref string . ref char 等都报错,如mscorlib.dll 异常.其他信息: 尝试读取或写入受保护的内存.这通常指 ...
- python3 获取电脑磁盘、CPU、内存使用情况
import psutil # cd C:\Python36-32\Scripts pip install psutil # 获取本机磁盘使用率和剩余空间G信息 def get_disk_info() ...
- Ubuntu 14.04/16.04/18.04安装最新版Eigen3.3.5
https://blog.csdn.net/xiangxianghehe/article/details/81236299 sudo cp -r /usr/local/include/eigen3 / ...
- DesktopLoader服务程序
program DesktopLoader; //{$APPTYPE CONSOLE} uses Windows,WinSvc,ShellApi; var s:String; iDesktops,jD ...
- ArcMAP中Excel数据转换为shp数据
参考百度知道:http://jingyan.baidu.com/article/f7ff0bfc1cf22c2e26bb138d.html 将数据库中带有X.Y坐标的二维表转换为空间点数据:从数据中将 ...