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
    }
}
相关推荐
夏乌_Wx4 小时前
练题100天——DAY23:存在重复元素Ⅰ Ⅱ+两数之和
数据结构·算法·leetcode
ada7_10 小时前
LeetCode(python)108.将有序数组转换为二叉搜索树
数据结构·python·算法·leetcode
独自破碎E10 小时前
加油站环路问题
java·开发语言·算法·leetcode
Swift社区10 小时前
LeetCode 445 - 两数相加 II
算法·leetcode·职场和发展
墨染点香10 小时前
LeetCode 刷题【187. 重复的DNA序列】
算法·leetcode·职场和发展
2401_8414956412 小时前
【LeetCode刷题】最大子数组和
数据结构·python·算法·leetcode·动态规划·最大值·最大子数组和
鹿角片ljp12 小时前
力扣101.判断对称二叉树-推荐掌握递归
算法·leetcode·职场和发展
2401_8414956412 小时前
【LeetCode刷题】最小覆盖字串
数据结构·python·算法·leetcode·字符串·双指针·滑动窗口算法
qk学算法13 小时前
力扣算法——二分最大值最小值
数据结构·算法·leetcode