博客
关于我
牛客网算法——名企高频面试题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/

    你可能感兴趣的文章
    Nginx的是什么?干什么用的?
    查看>>
    Nginx访问控制_登陆权限的控制(http_auth_basic_module)
    查看>>
    nginx负载均衡器处理session共享的几种方法(转)
    查看>>
    nginx负载均衡的5种策略(转载)
    查看>>
    nginx负载均衡的五种算法
    查看>>
    Nginx运维与实战(二)-Https配置
    查看>>
    Nginx配置ssl实现https
    查看>>
    Nginx配置TCP代理指南
    查看>>
    Nginx配置——不记录指定文件类型日志
    查看>>
    Nginx配置代理解决本地html进行ajax请求接口跨域问题
    查看>>
    Nginx配置参数中文说明
    查看>>
    Nginx配置好ssl,但$_SERVER[‘HTTPS‘]取不到值
    查看>>
    Nginx配置如何一键生成
    查看>>
    Nginx配置实例-负载均衡实例:平均访问多台服务器
    查看>>
    NHibernate学习[1]
    查看>>
    NIFI1.21.0通过Postgresql11的CDC逻辑复制槽实现_指定表多表增量同步_增删改数据分发及删除数据实时同步_通过分页解决变更记录过大问题_02----大数据之Nifi工作笔记0054
    查看>>
    NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_配置binlog_使用处理器抓取binlog数据_实际操作01---大数据之Nifi工作笔记0040
    查看>>
    NIFI从MySql中增量同步数据_通过Mysql的binlog功能_实时同步mysql数据_配置数据路由_实现数据插入数据到目标数据库_实际操作03---大数据之Nifi工作笔记0042
    查看>>
    NIFI同步MySql数据_到SqlServer_错误_驱动程序无法通过使用安全套接字层(SSL)加密与SQL Server_Navicat连接SqlServer---大数据之Nifi工作笔记0047
    查看>>
    Nifi同步过程中报错create_time字段找不到_实际目标表和源表中没有这个字段---大数据之Nifi工作笔记0066
    查看>>