206-反转链表

206-反转链表

力扣206

https://leetcode-cn.com/problems/reverse-linked-list/

简单题,链表题指针不怕多!!

1
2
3
4
5
6
7
8
9
10
11
public ListNode reverseList(ListNode head) {
if (head == null) return null;
ListNode pre = head, post = null, temp = null;
while (pre != null) {
temp = pre.next;
pre.next = post;
post = pre;
pre = temp;
}
return post;
}

其他链表类型的题目点击这里

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×