博客
关于我
牛客网算法——名企高频面试题143题(13)
阅读量:400 次
发布时间:2019-03-04

本文共 2610 字,大约阅读时间需要 8 分钟。

????

?????????????????????????????????????????????????????????????

???????

??

?????????????????????????????

  • ????????pre?curr??????????????????
  • ??????????????????
  • ?????????????????pre???????
  • ??pre?curr??????????????????
  • ???????pre????????????
  • ???????????O(n)???????O(1)???????????????

    ????

    public class ????II {    public class ListNode {        int val;        ListNode next;        public ListNode(int val) {            this.val = val;        }    }    public ListNode rever(ListNode head) {        if (head == null) {            return null;        }        ListNode pre = null;        ListNode curr = head;        while (curr != null) {            ListNode future = curr.next;            curr.next = pre;            pre = curr;            curr = future;        }        return pre;    }        public static void main(String[] args) {        // ????        ListNode s1 = new ListNode(1);        ListNode s2 = new ListNode(2);        ListNode s3 = new ListNode(3);        ListNode s4 = new ListNode(4);        s1.next = s2;        s2.next = s3;        s3.next = s4;        ListNode res = rever(s1);        while (res != null) {            System.out.println(res.val);            res = res.next;        }    }}

    ??????????

    ????????????????????????????????????????????

  • ????dummy??????????????
  • ???????????dummy?????????
  • ????????pre?curr?????dummy?????????
  • ????????????????????
  • ?????????dummy????????????????????
  • ????????O(n)???????O(1)???????

    ????

    public class ????II {    public class ListNode {        int val;        ListNode next;        public ListNode(int val) {            this.val = val;        }    }    public ListNode rever1(ListNode head) {        if (head == null) {            return null;        }        ListNode dumy = new ListNode(0);        dumy.next = head;        ListNode pre = dumy;        ListNode curr = head;        while (curr.next != null) {            ListNode future = curr.next;            curr.next = future.next;            future.next = dumy.next;            pre.next = future;        }        return dumy.next;    }        public static void main(String[] args) {        // ????        ListNode s1 = new ListNode(1);        ListNode s2 = new ListNode(2);        ListNode s3 = new ListNode(3);        ListNode s4 = new ListNode(4);        s1.next = s2;        s2.next = s3;        s3.next = s4;        ListNode res = rever1(s1);        while (res != null) {            System.out.println(res.val);            res = res.next;        }    }}

    ????

    ???????1?2?3?4???????4?3?2?1?????????????????

    4321

    ??

    ???????????????????????????????????????????????????????????????????????????????

    转载地址:http://wqch.baihongyu.com/

    你可能感兴趣的文章
    pyinstaller的使用
    查看>>
    pyinstaller超级加密 (加壳和转c)
    查看>>
    pyinstaller错误:OSError:找不到Python库:libpython3.4mu.so.1.0、libpython3.4m.so.1.0、libpython3.4.so.1.0
    查看>>
    Pyinstaller:‘;Fiona‘;没有属性‘;_loading‘;(很可能是由于循环导入)
    查看>>
    pyinstaller:更改应用程序图标
    查看>>
    Pylint“未解决的导入“;Visual Studio 代码中的错误
    查看>>
    pyLoad远程代码执行漏洞复现(CVE-2023-0297)
    查看>>
    pymongo update_one(),upsert=True,不使用$运算符
    查看>>
    pymongo 中的快速或批量更新
    查看>>
    pymongo删除操作
    查看>>
    PyMongo按多个关键点分组
    查看>>
    Pympress:强大的双屏PDF阅读器
    查看>>
    pymysql.err.InternalError: (1054, "Unknown column '27D24A3B' in 'where clause'")之错误解决
    查看>>
    pymysql.err.OperationalError: (1364, “Field ‘id‘ doesn‘t have a default value“)
    查看>>
    Pytorch Tensor 维度操作的形象理解 Tensor.unsqueeze() Tensor.squeeze()
    查看>>
    PyMySQL库对Mysql数据库进行增删改查与工具类封装
    查看>>
    pynput的基本介绍和使用
    查看>>
    pyodbc 通过 IIS7 连接到 MSSQL 2005 服务器
    查看>>
    PyPI 存储库中的 JarkaStealer:深入解析与防范措施
    查看>>
    Pyplot tutorial,Pyplot官方教程自翻译
    查看>>