当前位置: 首页 > news >正文

【LeetCode】206. 反转链表

leetcode链接 206. 反转链表
在这里插入图片描述

#include <stdio.h>

struct ListNode {
    int val;
    struct ListNode* next;
};
typedef struct ListNode ListNode;

struct ListNode* reverseList1(struct ListNode* head) {
    if (head != NULL) {
        ListNode* n1 = NULL;
        ListNode* n2 = head;
        ListNode* n3 = n2->next;
        while (n2 != NULL) {
            n2->next = n1;
            n1 = n2;
            n2 = n3;
            if (n3 != NULL) {
                n3 = n3->next;
            }
        }
        return n1;
    }
    return NULL;
}

ListNode* reverseList2(ListNode* head) {
    if (head) {
        ListNode* newhead = NULL;
        ListNode* cur = head;
        while (cur) {
            ListNode* next = cur->next;
            cur->next = newhead;
            newhead = cur;
            cur = next;
        }
        return newhead;
    }
    return NULL;
}

相关文章:

  • Python GUI库大汇总
  • Keil 的安装
  • Spring IOC原理
  • 【协议】XMLHttpRequest的梳理和总结
  • 高并发大游戏如何选择阿里云服务器配置?
  • MySQL窗口函数(MySQL Window Functions)
  • 安全审查常见要求
  • 橘子学Mybatis07之Mybatis关于缓存的设计
  • 【计算机硬件】2、指令系统、存储系统和缓存
  • 力扣(144. 二叉树的前序遍历94.二叉树的中序遍历145. 二叉树的后序遍历)
  • 阿里云国外服务器价格表
  • OSI七层协议和五层协议
  • 美颜技术对比:如何根据项目选择不同的美颜SDK?
  • Win10恢复环境是什么?
  • Blender——将模型及其所有纹理与材质导入unity
  • [Python练习]使用Python爬虫爬取豆瓣top250的电影的页面源码
  • 怎么修改或移除WordPress后台仪表盘概览底部的版权信息和主题信息?
  • What is `HttpServletRequestWrapper` does?
  • Mac ❀ 如何在MacOS上安装pip软件包
  • 为什么要用B+树
  • 加强战略矿产出口全链条管控将重点开展哪些工作?商务部答问
  • 日本广岛大学一处拆迁工地发现疑似未爆弹
  • 缺字危机:一本书背后有多少“不存在”的汉字?
  • 技术派|更强的带刀侍卫:从054B型战舰谈谈世界护卫舰发展
  • 英国首相斯塔默住所起火,警方紧急调查情况
  • 济南市委副秘书长吕英伟已任历下区领导