#力扣 LeetCode面试题 17.12. BiNode @FDDLC
发布日期:2021-06-30 21:05:03 浏览次数:2 分类:技术文章

本文共 533 字,大约阅读时间需要 1 分钟。

题目描述:

 

Java代码:

/** * Definition for a binary tree node. * public class TreeNode { *     int val; *     TreeNode left; *     TreeNode right; *     TreeNode(int x) { val = x; } * } */class Solution {    TreeNode ans,pre;//初值默认为null    public void go(TreeNode cur){        if(cur==null)return;        go(cur.left);        cur.left=null;//左结点用完后置空        if(pre==null)ans=cur;        else pre.right=cur;        pre=cur;        go(cur.right);    }    public TreeNode convertBiNode(TreeNode root) {        go(root);        return ans;    }}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

转载地址:https://liuxingchang.blog.csdn.net/article/details/116462302 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:#Java序列化、反序列化、Serializable、serialVersionUID @FDDLC
下一篇:#力扣 LeetCode面试题 16.07. 最大数值 @FDDLC

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月15日 20时34分14秒