LintCode(Flatten Binary Tree to Linked List)翻转二叉树为链表 的变体
来源:互联网 发布:依云软件官方网站 编辑:程序博客网 时间:2024/06/05 05:55
Flatten Binary Tree to Linked List (深度优先搜索)
翻转二叉树为链表
/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = val; * this.left = this.right = null; * } * } */public class Solution { /** * @param root: a TreeNode, the root of the binary tree * @return: nothing */ public void flatten(TreeNode root) { if(root == null)return; flattenSubTree(root); } private TreeNode flattenSubTree(TreeNode root){ if (root == null){ return null; }else if (root.left == null && root.right == null){ return root; }else{ TreeNode left = root.left; TreeNode right = root.right; root.left = null; if (left != null){ root.right = left; TreeNode temp = flattenSubTree(left); temp.left = null; if (right != null){ temp.right = right; }else{ return temp; } } return flattenSubTree(right); } }}
0 0
- LintCode(Flatten Binary Tree to Linked List)翻转二叉树为链表 的变体
- Flatten Binary Tree to Linked List 将二叉树转换为链表
- lintcode-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:二叉树变更结构
- lintcode- Flatten Binary Tree to Linked List-453
- 5.1.11—二叉树的遍历—Flatten Binary Tree to Linked List
- 树的操作-将树变为链表(Flatten Binary Tree to Linked List)
- leetcode 114.Flatten Binary Tree to Linked List (将二叉树转换链表) 解题思路和方法
- Flatten Binary Tree to Linked List (二叉树转前序链表)【leetcode】
- 【leetcode 二叉树摊直】Flatten Binary Tree to Linked List
- 将二叉树拆成链表 Flatten Binary Tree to Linked List
- lintcode flatten-binary-tree-to-linked-list 将二叉树拆成链表 前序扁平化 中序扁平化
- 114Flatten Binary Tree to Linked List 二叉树到单链表的扁平化处理
- 二叉搜索树转换为双向链表 binary search tree to double-linked list
- 这么多年的土豆都白吃了!土豆还能这么做,太香了
- MATLAB 牛顿插值法程序
- Bug猜想(一)
- 五本编译原理的书
- 编程珠玑题目集锦
- LintCode(Flatten Binary Tree to Linked List)翻转二叉树为链表 的变体
- VMware的网卡配置之linux
- Day 8(11.15):存储过程(3)--扩展存储过程
- memmove,memcopy区别和实现
- 《将来的你, 一定会那“啥啥啥”》 某某
- java基础知识点二(下)
- 图的广度搜索bfs,邻接表实现
- jdk环境变量配置
- 猴子搬香蕉问题