反转链表


public class Solution {

    public ListNode reverseList(ListNode head) {

        ListNode H=new ListNode(0);

        H.next=null;

        ListNode p=head;

        while(p!=null)

        {

            ListNode x=p;

            p=p.next;

            x.next=H.next;

            H.next=x;

        }

        return H.next;

    }

}