LeetCode_209_ReverseLinkedList
题目解析:
注意这里是没有头结点的链表,每个节点都有值。
解法:
public static ListNode reverseList(ListNode head) {
if(null == head)
return head;
ListNode preNode = null;
ListNode nextNode = null;
while(null != head.next){
nextNode = head.next;
head.next = preNode;
preNode = head;
head = nextNode;
}
head.next = preNode;
return head;
}
网友评论