• 二叉树展开为链表


    前序遍历+重赋值

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     *     int val;
     *     TreeNode left;
     *     TreeNode right;
     *     TreeNode() {}
     *     TreeNode(int val) { this.val = val; }
     *     TreeNode(int val, TreeNode left, TreeNode right) {
     *         this.val = val;
     *         this.left = left;
     *         this.right = right;
     *     }
     * }
     */
    class Solution {
        List<Integer> list = new ArrayList<>();
        public void flatten(TreeNode root) {
            if(root == null) return ;
            preOrder(root);
            int i = 0;
            while(i +1 < list.size()){
                root.left = null;
                root.right = new TreeNode(list.get(i+1));
                root = root.right;   
                i++;          
            }
    
        }
        public void preOrder(TreeNode root){
            if(root == null) return ;
            list.add(root.val);
            preOrder(root.left);
            preOrder(root.right);
        }
        
    }
    
    

  • 相关阅读:
    时序图
    用例图
    欢迎界面(闪屏)
    WBS
    闲来听书
    软件团队的模式
    结对编程
    在个人项目中,找bug,审核代码.
    时序图
    部分功能的实现
  • 原文地址:https://www.cnblogs.com/cstdio1/p/13419748.html
Copyright © 2020-2023  润新知