zoukankan      html  css  js  c++  java
  • 反转链表

    反转链表

    输入一个链表,反转链表后,输出新链表的表头。

    代码实现

    package 剑指offer;

    /**
     * @author WangXiaoeZhe
     * @Date: Created in 2019/11/22 15:46
     * @description:
     */

    public class Main7 {
        public static void main(String[] args) {

        }

        public class ListNode {
            int val;
            ListNode next = null;

            ListNode(int val) {
                this.val = val;
            }
        }

        public ListNode ReverseList(ListNode head){
            if (head == null) {
                return null;
            }
            ListNode pre=null;
            ListNode next=null;
            while (head != null) {
                /**
                 * 标记第二个元素
                 */

                next=head.next;
                head.next=pre;
                pre=head;
                head=next;
            }
            return pre;
        }
    }
  • 相关阅读:
    javascript 自定义事件
    javascript 实现HashTable(哈希表)
    NHibernate输出SQL语句
    Asp.net MVC Comet推送
    MySQL 数据备份与还原
    Mysql -- 慢查询
    cookie 的HttpOnly 和 Secure 属性
    Ubuntu -- 反射shell nc
    docker 访问宿主机网络
    k8s 配置文件 详解
  • 原文地址:https://www.cnblogs.com/wuhen8866/p/11912077.html
Copyright © 2011-2022 走看看