当前位置:网站首页>11. Linked list inversion

11. Linked list inversion

2022-07-28 10:16:00 [email protected]

  • Input : 1->2->3->4->5->NULL
    Output : 5->4->3->2->1->NULL
public ListNode reverseList(ListNode head) {
        ListNode cur = null, pre = head;
        while(pre != null){
            ListNode t = pre.next;
            pre.next = cur;
            cur = pre;
            pre = t;
        }
        return cur;
    }

Running results
 Insert picture description here

原网站

版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280958224242.html