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 ...
随机推荐
- 两台群晖之间传输数据NFS
如何在两台局域网的群晖之间传输数据,可以用NFS的方式来实现.摘抄如下,地址http://www.nasyun.com/thread-64638-1-1.html?reload=true 假设要把群晖 ...
- leetcode-162周赛-1253-重构二进制矩阵
题目描述: 自己的提交: class Solution: def reconstructMatrix(self, upper: int, lower: int, colsum: List[int]) ...
- Windows 获取windows密码
#include <iostream> #define Main main #define COLOR_GREEN system("color 2"); #includ ...
- Windows 屏幕保护程序
{ 创建一个win32 窗口项目,不是控制台的 把exe改为src文件 复制到windows目录下 ok }
- Delphi 左键代替右键
Delphi 左键代替右键: var Pt: TPoint; begin GetCursorPos(Pt); PopupMenu1.Popup(Pt.X, Pt.Y); end;
- go结构体上的函数
go结构体上的函数 我们可以将一个方法和一个结构体关联: type Saiyan struct { Name string Power int } func (s *Saiyan) Super() { ...
- Eclipse 安装Activiti插件
建议使用vpn或其他翻墙手段安装(否则下载速度可能很慢) 我的博客中有介绍如何自己搭建属于自己的ssr,https://www.cnblogs.com/zktww/p/10839347.html(由于 ...
- 使用HBuilder编辑器进行真机调试运行时提示Waiting for debugger!
在使用HBuilder编辑器创建mui项目进行真机调试的时候,手机总是提示Waiting for debugger! 现在终于找到了解决办法: 手机 设置 -> 开发人员选项 -> USB ...
- NX二次开发-Block UI C++界面Body Collector(体收集器)控件的获取(持续补充)
Body Collector(体收集器)控件的获取 NX9+VS2012 #include <uf.h> #include <uf_obj.h> UF_initialize() ...
- FastJson乱序问题
1.初始化为有序json对象 JSONObject jsonOrdered= new JSONObject(true); 2.将String对象转换过程中,不要调整顺序 JSONObject json ...