114 Flatten Binary Tree to Linked List [Python]
114 Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.
将二叉树展开成链表
[]
(D:\dataStructure\Leetcode\114.png)
思路:将根节点与左子树相连,再与右子树相连。递归地在每个节点的左右孩子节点上,分别进行这样的操作。
代码
class Solution(object):
def flatten(self, root):
if root == None:
return
if root.left == None and root.right == None:
return
self.flatten(root.left)
self.flatten(root.right)
tmp = root.left
root.right = root.left
root.left = None
while root.right:
root = root.right
root.right = tmp
114 Flatten Binary Tree to Linked List [Python]的更多相关文章
- 114. Flatten Binary Tree to Linked List(M)
. Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in-place. For ...
- LeetCode 114| Flatten Binary Tree to Linked List(二叉树转化成链表)
题目 给定一个二叉树,原地将它展开为链表. 例如,给定二叉树 1 / \ 2 5 / \ \ 3 4 6 将其展开为: 1 \ 2 \ 3 \ 4 \ 5 \ 6 解析 通过递归实现:可以用先序遍历, ...
- 【LeetCode】114. Flatten Binary Tree to Linked List
Flatten Binary Tree to Linked List Given a binary tree, flatten it to a linked list in-place. For ex ...
- [LeetCode]题解(python):114 Flatten Binary Tree to Linked List
题目来源 https://leetcode.com/problems/flatten-binary-tree-to-linked-list/ Given a binary tree, flatten ...
- 【LeetCode】114. Flatten Binary Tree to Linked List 解题报告(Python & C++ & Java)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 先序遍历 递归 日期 题目地址:https://le ...
- [LeetCode] 114. Flatten Binary Tree to Linked List 将二叉树展开成链表
Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ...
- [LeetCode] 114. Flatten Binary Tree to Linked List 将二叉树展平为链表
Given a binary tree, flatten it to a linked list in-place. For example, given the following tree: 1 ...
- LeetCode OJ 114. Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ...
- 114. Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place. For example,Given 1 / \ 2 5 / \ \ 3 4 6 T ...
随机推荐
- linux下光标操作
Ctrl+左右键 单词间跳转 Ctrl+a 跳到行首 Ctrl+e 跳到行尾 Ctrl+u 删除当前光标前的文字 Ctrl+k 删除当前光标后的文字 Ctrl+w ...
- Python实现简单Web服务器
实验楼教程链接: https://www.shiyanlou.com/courses/552/labs/1867/document http原理详解(http下午茶): https://www.kan ...
- 百度测试架构师眼中的百度QA
百度测试架构师眼中的百度QA(一) 发表于2013-04-09 15:31| 4004次阅读| 来源架构师Jack的个人空间| 13 条评论| 作者董杰 百度测试QA 摘要:一直以来百度质量部在业 ...
- Python-添加psutil模块到python2.7版本
一.问题描述 1.导入模块psutil时提示报错:ImportError: No module named psutil 2.下载psutil模块后,安装python setup.py install ...
- 达拉草201771010105《面向对象程序设计(java)》第七周学习总结
达拉草201771010105<面向对象程序设计(java)>第七周学习总结 实验七继承附加实验 实验时间 2018-10-11 1.实验目的与要求 (1)进一步理解4个成员访问权限修饰符 ...
- Windows 10 右键 在此处打开 CMD
1. 打开注册表 # 1. 使用快捷键打开 “运行” # win + r # 2. 在 “运行” 中输入 # regedit # 3. 回车 2. 创建与设置 OpenCMDHere # 1. 切换到 ...
- Pycharm+PyQt5开发环境配置
一.安装Python开发环境 python官网下载地址:https://www.python.org/downloads/ 注:千万不要使用最新测试版,很有可能第三方库不支持 笔者目前使用的版本是3. ...
- Spring,SpringMVC,MyBatis,SSM配置文件比较
Spring配置文件: applicationContext.xml applicationContext.xml是Spring的核心配置文件 IOC/DI,AOP相关配置都是在这个文件中 Sprin ...
- DSO 运行 —— dso_ros + Android 手机摄像头
转载请注明出处,谢谢 原创作者:Mingrui 原创链接:https://www.cnblogs.com/MingruiYu/p/12425855.html 本文要点: dso 配置安装 dso 离线 ...
- overflow-y:auto/hidden/scroll和overflow-x:visible组合渲染异常
最近做项目想做一个这样的效果:就是我想要内部div x轴溢出div则显示y轴溢出div则出现滚动条于是用到了overflow-y 和 overflow-x 这个css属性原来以为css中直接设置就ok ...