Golang | Leetcode Golang题解之第114题二叉树展开为链表

题目:

题解:

Go 复制代码
func flatten(root *TreeNode)  {
    curr := root
    for curr != nil {
        if curr.Left != nil {
            next := curr.Left
            predecessor := next
            for predecessor.Right != nil {
                predecessor = predecessor.Right
            }
            predecessor.Right = curr.Right
            curr.Left, curr.Right = nil, next
        }
        curr = curr.Right
    }
}
相关推荐
qq_1728055926 分钟前
Go 自建库的使用教程与测试
开发语言·后端·golang
共享家95272 小时前
优先搜索(DFS)实战
算法·leetcode·深度优先
007php0074 小时前
某大厂MySQL面试之SQL注入触点发现与SQLMap测试
数据库·python·sql·mysql·面试·职场和发展·golang
flashlight_hi4 小时前
LeetCode 分类刷题:2563. 统计公平数对的数目
python·算法·leetcode
雨中散步撒哈拉4 小时前
13、做中学 | 初一下期 Golang数组与切片
开发语言·后端·golang
0wioiw04 小时前
Go基础(③Cobra)
开发语言·后端·golang
楼田莉子4 小时前
C++算法专题学习:栈相关的算法
开发语言·c++·算法·leetcode
dragoooon344 小时前
[数据结构——lesson3.单链表]
数据结构·c++·leetcode·学习方法
轮到我狗叫了5 小时前
力扣.1054距离相等的条形码力扣767.重构字符串力扣47.全排列II力扣980.不同路径III力扣509.斐波那契数列(记忆化搜索)
java·算法·leetcode
dragoooon347 小时前
[优选算法专题二滑动窗口——串联所有单词的子串]
数据结构·c++·学习·算法·leetcode·学习方法