上班摸鱼刷算法-Java-hot100-[206]反转链表

class Solution {
    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode preNode = null;
        ListNode nextNode = head;
        while (head != null) {
            nextNode = head.next;
            head.next = preNode;
            preNode = head;
            head = nextNode;
        }
        return preNode;
    }

 

posted on 2023-07-20 17:15  Hi,Bro  阅读(4)  评论(0编辑  收藏  举报