美文网首页
leetcode刷题-206.反转一个单链表

leetcode刷题-206.反转一个单链表

作者: 五年老码农 | 来源:发表于2020-02-09 00:03 被阅读0次

反转一个单链表。

示例:

输入: 1->2->3->4->5->NULL
输出: 5->4->3->2->1->NULL

一个很简单的链表题代码如下:

class Solution {
    public ListNode reverseList(ListNode head) {
        if(head==null||head.next==null){
            return head;
        }
        ListNode p = reverseList(head.next);
        head.next.next = head;
        head.next= null;
     return p;
    }
}

相关文章

网友评论

      本文标题:leetcode刷题-206.反转一个单链表

      本文链接:https://www.haomeiwen.com/subject/rviwxhtx.html