题目:
吐槽:反转链表经典的解题步骤,通过pre head next三个标志位进行转换进行反转。熟能生巧的思路,多练习,就记住了
代码:
public ListNode reverseList(ListNode head) {
//定义好辅助标记位,其顺序是pre head next
ListNode pre = null;
ListNode next;
while(head!=null){
next = head.next;
head.next = pre;
pre = head;
head = next;
}
return pre;
}