重拾算法之剑指Offier——反转链表

来源:互联网 发布:信息安全与密码学编程 编辑:程序博客网 时间:2024/05/18 15:28

剑指Offier——反转链表

题目描述
输入一个链表,反转链表后,输出链表的所有元素。

public class Solution {    public ListNode ReverseList(ListNode head) {        ListNode listNode = null;        ListNode p = null;        while(head!=null){            p = head.next;            head.next = listNode;            listNode = head;            head = p;        }        return listNode;    }}
1 0
原创粉丝点击