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
    }
}
相关推荐
样例过了就是过了6 分钟前
LeetCode热题100 分割回文串
数据结构·c++·算法·leetcode·深度优先·dfs
Morwit1 小时前
【力扣hot100】 85. 最大矩形
c++·算法·leetcode·职场和发展
啊哦呃咦唔鱼2 小时前
LeetCode hot100-438 找到字符串中所以字母异位词
算法·leetcode·职场和发展
重生之后端学习2 小时前
136. 只出现一次的数字
开发语言·算法·leetcode·职场和发展·深度优先
luckycoding2 小时前
LCR 014.字符串的排列
leetcode
smj2302_796826522 小时前
解决leetcode第3869题.统计区间内奇妙数的数目
python·算法·leetcode
TracyCoder1232 小时前
LeetCode Hot100(66/100)——118. 杨辉三角
算法·leetcode·职场和发展
葳_人生_蕤2 小时前
Leetcode HOT 100
算法·leetcode·职场和发展
无尽的罚坐人生3 小时前
hot 100 35. 搜索插入位置
数据结构·算法·leetcode·二分查找
葳_人生_蕤3 小时前
力扣Hot100——234.回文链表
算法·leetcode·链表