核心思想:遍历
老题目了,之前做过。
/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode ReverseList(ListNode head) {
ListNode head1 = new ListNode(0);
head1.next = head;
ListNode pre, cur;
pre = null;
cur = head;
while(head1.next != null){
head1.next = cur.next;
cur.next = pre;
pre = cur;
cur = head1.next;
}
return pre;
}
}