Flatten Binary Tree to Linked List
来源:互联网 发布:游戏碎片整理软件 编辑:程序博客网 时间:2024/05/22 09:47
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { // Pre-order traverse, append current node to the linked list. private static TreeNode linkedListEnd = null; public void flatten(TreeNode root) { if (root == null) return; TreeNode left = root.left; TreeNode right = root.right; if (linkedListEnd != null){ // Append current node to linked list linkedListEnd.right = root; linkedListEnd.left = null; } // If linked list is empty, just set root to linkedListEnd linkedListEnd = root; flatten(left); flatten(right); }}
0 0
- 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
- Flatten Binary Tree to Linked List
- Spark Streaming:大规模流式数据处理的新贵
- dhtmlxTree 介绍
- SQL Server修改列的类型时,弹出不允许保存更改对话框的解决方法
- TOMCAT内存溢出
- Dynamics CRM2013 业务规则的新建、激活与删除
- Flatten Binary Tree to Linked List
- protobuf的安装
- java 排序算法实现 其五:希尔排序
- PAT 1023. Have Fun with Numbers (20)
- 简单的TestNG.xml在Eclipse中跑TestNG suite
- 当今世界十大经典算法
- Css控制显示文本个数
- IOS开发之使用Speex格式实现简单的语音聊天功能(二)
- JAVA文件的上传与下载的例子