LeetCode 206. 反转链表

题目链接:https://leetcode-cn.com/problems/reverse-linked-list/

反转一个单链表。

示例:

输入: 1->2->3->4->5->NULL
输出: 5->4->3->2->1->NULL
进阶:
你可以迭代或递归地反转链表。你能否用两种方法解决这道题?

 1 /**
 2  * Definition for singly-linked list.
 3  * struct ListNode {
 4  *     int val;
 5  *     struct ListNode *next;
 6  * };
 7  */
 8 struct ListNode* reverseList(struct ListNode* head){
 9     struct ListNode* pre=NULL;
10     struct ListNode* cur=head;
11     while(cur){
12         struct ListNode* temp=cur->next;
13         cur->next=pre;
14         pre=cur;
15         cur=temp;
16     }
17     return pre;
18 }
原文地址:https://www.cnblogs.com/shixinzei/p/11350871.html