1、前言
题目描述2、思路
双指针
3、代码
class Solution {
public ListNode reverseList(ListNode head) {
if(head == null){
return null;
}
ListNode dummy = new ListNode(-1);
while (head != null){
ListNode next = dummy.next;
ListNode temp = head.next;
dummy.next = head;
head.next = next;
head = temp;
}
return dummy.next;
}
}
网友评论