题目描述
思路:双指针算法
方法一:
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode reverseList(ListNode head) {
ListNode curNode = head;
ListNode nextNode;
ListNode preNode = null;
while (curNode != null) {
nextNode = curNode.next;
curNode.next = preNode;
preNode = curNode;
curNode = nextNode;
}
return preNode;
}
}
标签:ListNode,val,int,next,链表,Hot,LeetCode206,preNode,curNode
From: https://www.cnblogs.com/keyongkang/p/17876931.html