Golang | Leetcode Golang题解之第92题反转链表II

题目:

题解:

Go 复制代码
func reverseBetween(head *ListNode, left, right int) *ListNode {
    // 设置 dummyNode 是这一类问题的一般做法
    dummyNode := &ListNode{Val: -1}
    dummyNode.Next = head
    pre := dummyNode
    for i := 0; i < left-1; i++ {
        pre = pre.Next
    }
    cur := pre.Next
    for i := 0; i < right-left; i++ {
        next := cur.Next
        cur.Next = next.Next
        next.Next = pre.Next
        pre.Next = next
    }
    return dummyNode.Next
}
相关推荐
转调4 分钟前
每日一练:地下城游戏
开发语言·c++·算法·leetcode
千年死缓1 小时前
go+redis基于tcp实现聊天室
redis·tcp/ip·golang
huanxiangcoco1 小时前
152. 乘积最大子数组
python·leetcode
希望有朝一日能如愿以偿3 小时前
力扣题解(飞机座位分配概率)
算法·leetcode·职场和发展
Espresso Macchiato3 小时前
Leetcode 3306. Count of Substrings Containing Every Vowel and K Consonants II
leetcode·滑动窗口·leetcode medium·leetcode 3306·leetcode周赛417
数据分析螺丝钉4 小时前
力扣第240题“搜索二维矩阵 II”
经验分享·python·算法·leetcode·面试
￴ㅤ￴￴ㅤ9527超级帅4 小时前
LeetCode hot100---数组及矩阵专题(C++语言)
c++·leetcode·矩阵
吃着火锅x唱着歌5 小时前
Redis设计与实现 学习笔记 第五章 跳跃表
golang
鱼跃鹰飞5 小时前
Leecode热题100-295.数据流中的中位数
java·服务器·开发语言·前端·算法·leetcode·面试
技术卷8 小时前
Redis数据库与GO完结篇:redis操作总结与GO使用redis
数据库·redis·golang