递归---Flatten Binary Tree to Linked List
来源:互联网 发布:欧美网络教育本科文凭 编辑:程序博客网 时间:2024/06/05 15:47
Flatten a binary tree to a fake “linked list” in pre-order traversal.
Here we use the right pointer in TreeNode as the next pointer in ListNode.
public class Solution { private TreeNode lastNode = null; public void flatten(TreeNode root) { if (root == null) { return; } if (lastNode != null) { lastNode.left = null; lastNode.right = root; } lastNode = root; TreeNode right = root.right; flatten(root.left); flatten(right); }}
0 0
- 递归---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
- 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
- Flatten Binary Tree to Linked List
- Flatten Binary Tree to Linked List
- LeetCode - Flatten Binary Tree to Linked List
- 【leetcode】Flatten Binary Tree to Linked List
- Flatten Binary Tree to Linked List
- [LeetCode]Flatten Binary Tree to Linked List
- Flatten Binary Tree to Linked List
- Flatten Binary Tree to Linked List
- [乙女向]兄弟战争闪亮蔚蓝+激情粉【PSP汉化版】日文版[带全开档+中文攻略]
- bzoj 1977: [BeiJing2010组队]次小生成树 Tree
- lintcode: Unique Binary Search Trees
- C++中的this指针
- 排序算法之希尔排序(Java)
- 递归---Flatten Binary Tree to Linked List
- MYBATIS+SPRING 配置
- 杭电5562
- 一道腾讯笔试题--Integer的比较
- String、StringBuffer和StringBuilder
- 设计模式2#多例
- UVA 147 Dollars(完全背包)
- JAVA注解
- 杭电5567