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

    你可能感兴趣的文章
    Openlayers高级交互(17/20):通过坐标显示多边形,计算出最大幅宽
    查看>>
    Openlayers高级交互(18/20):根据feature,将图形适配到最可视化窗口
    查看>>
    Openlayers高级交互(19/20): 地图上点击某处,列表中显示对应位置
    查看>>
    Openlayers高级交互(2/20):清除所有图层的有效方法
    查看>>
    Openlayers高级交互(20/20):超级数据聚合,页面不再混乱
    查看>>
    Openlayers高级交互(3/20):动态添加 layer 到 layerGroup,并动态删除
    查看>>
    Openlayers高级交互(4/20):手绘多边形,导出KML文件,可以自定义name和style
    查看>>
    Openlayers高级交互(5/20):右键点击,获取该点下多个图层的feature信息
    查看>>
    Openlayers高级交互(6/20):绘制某点,判断它是否在一个电子围栏内
    查看>>
    Openlayers高级交互(7/20):点击某点弹出窗口,自动播放视频
    查看>>
    Openlayers高级交互(8/20):选取feature,平移feature
    查看>>
    Openlayers高级交互(9/20):编辑图形(放缩、平移、变形、旋转),停止编辑
    查看>>
    Openlayers:DMS-DD坐标形式互相转换
    查看>>
    openlayers:圆孔相机根据卫星经度、纬度、高度、半径比例推算绘制地面的拍摄的区域
    查看>>
    OpenLDAP(2.4.3x)服务器搭建及配置说明
    查看>>
    OpenLDAP编译安装及配置
    查看>>
    Openmax IL (二)Android多媒体编解码Component
    查看>>
    OpenMCU(一):STM32F407 FreeRTOS移植
    查看>>
    OpenMCU(三):STM32F103 FreeRTOS移植
    查看>>
    OpenMCU(三):STM32F103 FreeRTOS移植
    查看>>