LeetCode题解:Flatten Binary Tree to Linked List
来源:互联网 发布:网络繁忙请稍后再试 编辑:程序博客网 时间:2024/05/19 02:21
Given a binary tree, flatten it to a linked list in-place.
For example,
Given
1 / \ 2 5 / \ \ 3 4 6
The flattened tree should look like:
1
\
2
\
3
\
4
\
5
\
6
题意:看不懂……弄了几棵树跑结果发现是先序遍历
解决思路:先序遍历
代码:
public class Solution { public void flatten(TreeNode root) { if (root == null) { return; } if (root.left == null && root.right == null) { return; } while (root != null) { if (root.left == null) { root = root.right; continue; } TreeNode left = root.left; while (left.right != null) { left = left.right; } left.right = root.right; root.right = root.left; root.left = null; root = root.right; } }}
0 0
- LeetCode题解: Flatten Binary Tree to Linked List
- LeetCode 题解(51): Flatten Binary Tree to Linked List
- LeetCode题解:Flatten Binary Tree to Linked List
- LeetCode题解——Flatten Binary Tree to Linked List
- 【M】【83】【leetcode题解】Flatten Binary Tree to Linked List
- LeetCode题解-114-Flatten Binary Tree to Linked List
- leetcode Flatten Binary Tree to Linked List C++题解
- LeetCode: Flatten Binary Tree to Linked List
- LeetCode Flatten Binary Tree to Linked List
- LeetCode: Flatten Binary Tree to Linked List
- [Leetcode] Flatten Binary Tree to Linked List
- [LeetCode] Flatten Binary Tree to Linked List
- Leetcode: Flatten Binary Tree to Linked List
- leetcode Flatten Binary Tree to Linked List
- LeetCode Flatten Binary Tree to Linked List
- LeetCode - Flatten Binary Tree to Linked List
- 【leetcode】Flatten Binary Tree to Linked List
- [LeetCode]Flatten Binary Tree to Linked List
- ng 机器学习第二讲
- 三色旗
- IOS开发笔记-01按钮操作-05.IBAction&IBOutlet 06.加法计算器小结 07.关闭键盘
- 1 java程序设计概述
- Unity 下简易状态机的实现
- LeetCode题解:Flatten Binary Tree to Linked List
- codeforces 466D Increase Sequence DP
- LeetCode题解:Populating Next Right Pointers in Each Node
- equal和==的区别(原理讲解)
- Mysql命令大全
- 下载微软虚拟学院视频字幕,解决本地播放没有字幕
- TCP/IP详解卷1 读书笔记:第七章 Ping程序
- LeetCode题解:Triangle
- Java学习笔记----封装和private关键字