链表逆序

public ListNode reverseList(ListNode head){
        ListNode newHead = new ListNode();
        while(head!=null){
            ListNode next = head.next;
            head.next = newHead.next;
            newHead.next = head;
            head = next;
        }
        return newHead.next;
    }

 

posted @ 2020-08-06 14:58  helloworldmybokeyuan  阅读(69)  评论(0编辑  收藏  举报