本文内容:
1、题目
2、解答
3、递归解答
1、题目
Reverse a singly linked list.
2、解答
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode reverseList(ListNode head) {
//反转链表充分体现了临时节点的概念、指针的强大
ListNode front = null;
ListNode after = null;
while(head!=null){
after = head.next;
head.next = front;
front = head;
head = after;
}
}
}