牛客网:输入一个链表,反转链表后,输出新链表的表头。
/*
public class ListNode {
int val;
ListNode next = null;
ListNode(int val) {
this.val = val;
}
}*/
public class Solution {
public ListNode ReverseList(ListNode head) {
ListNode current = head;
ListNode front = null;
ListNode f_front = null;
while (current != null) {
f_front = front;
front = current;
current = current.next;
front.next = f_front;
}
return front;
}
}