题目:
反转链表,输入一个链表,输入该链表的反转
解析:
这道题没有什么思想,就是最基本的链表运算,但是牵扯了很多指针的变换,所以,经常拿出来考,大家熟记就好了
/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode ReverseList(ListNode head) {
ListNode pre = null;
ListNode next = null;
while(head != null){
next = head.next;
head.next = pre;
pre = head;
head = next;
}
return pre;
}
}