剑指Offer——15.反转链表
题目描述
输入一个链表,反转链表后,输出新链表的表头。
思路:
两个指针,循环调节指针方向。
代码:
public class Solution {
public ListNode ReverseList(ListNode head) {
ListNode pre = null;
ListNode p = null;
while(head != null){
p = head.next;
head.next = pre;
pre = head;
head = p;
}
return pre;
}
}
深信服公司福利 762人发布