【剑指Offer 24】反转链表
作者:互联网
双指针
/**
* 剑指 Offer 24. 反转链表
* https://leetcode.cn/problems/fan-zhuan-lian-biao-lcof/
*
* 思路:双指针
* */
public class Solution1 {
public ListNode reverseList(ListNode head) {
if (head == null || head.next == null) {
return head;
}
ListNode prev = null;
ListNode next = head;
while (next != null) {
ListNode temp = next.next;
next.next = prev;
prev = next;
next = temp;
}
return prev;
}
}
递归/栈
暂时想不出来
标签:24,head,prev,ListNode,Offer,next,链表,null 来源: https://www.cnblogs.com/liaozibo/p/offer-24.html