算法竞赛备赛——【数据结构】链表

链表

原地逆置

206. 反转链表 - 力扣(LeetCode)

C++ 复制代码
class Solution {
public:
    ListNode* reverseList(ListNode* head) {//链表无头节点 原地逆置 
        ListNode* pre=head;
        ListNode* cur=NULL;
        ListNode* t=NULL;//t=head->next 若head指向空链表会报错 非法访问其他空间
        while(pre!=NULL){
            t=pre->next;
            pre->next=cur;
            cur=pre;
            pre=t;
        }
        head=cur;
        return head;
    }
};

快慢指针

LCR 140. 训练计划 II - 力扣(LeetCode)

让两个指针相差k个 只用遍历一轮

C++ 复制代码
class Solution {
public:
    ListNode* trainingPlan(ListNode* head, int cnt) {
        ListNode* f=head;//fast
        ListNode* s=head;//slow
        int count=0;
        while(f!=NULL&&count<cnt){
            count++;
            f=f->next;
        }
        while(f!=NULL){
            f=f->next;
            s=s->next;
        }
        return s;
    }
};

静态链表

用数组描述的链表

跳表

跳跃表、跳跃列表,在有序链表的基础上增加了"跳跃"的功能,有序链表实现而二分查找。

1206. 设计跳表 - 力扣(LeetCode)

有点复杂 暂时不需要做

相关推荐
田梓燊3 小时前
2026/4/11 leetcode 3741
数据结构·算法·leetcode
斯内科3 小时前
FFT快速傅里叶变换
算法·fft
葳_人生_蕤3 小时前
hot100——栈和队列
数据结构
2301_822703203 小时前
开源鸿蒙跨平台Flutter开发:幼儿疫苗全生命周期追踪系统:基于 Flutter 的免疫接种档案与状态机设计
算法·flutter·华为·开源·harmonyos·鸿蒙
贵慜_Derek3 小时前
Managed Agents 里,Harness 到底升级了什么?
人工智能·算法·架构
feng_you_ying_li3 小时前
c++之哈希表的介绍与实现
开发语言·c++·散列表
2301_822703204 小时前
鸿蒙flutter三方库实战——教育与学习平台:Flutter Markdown
学习·算法·flutter·华为·harmonyos·鸿蒙
Jia ming4 小时前
C语言实现日期天数计算
c语言·开发语言·算法
xh didida4 小时前
C++ -- string
开发语言·c++·stl·sring
m晴朗4 小时前
测试覆盖率从35%到80%:我用AI批量生成C++单元测试的完整方案
c++·gpt·ai