设为首页 加入收藏

TOP

206. Reverse Linked List 解题记录
2018-10-21 18:11:32 】 浏览:120
Tags:206. Reverse Linked List 解题 记录

题目描述:

Reverse a singly linked list.

解题思路:

可用递归的方法对链表进行反转。

代码:

 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     if(head==NULL||head->next==NULL)
10         return head;
11     struct ListNode *p=reverseList(head->next);
12     head->next->next=head;
13     head->next=NULL;
14     return p;
15 }

解题收获:

温习了基本的递归思想和链表的使用。但做的时候还是迷茫了很久,说明对链表的使用还是不太熟悉。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇(1)基于事件的任务调度器 下一篇链表补充及链表和数组的区别

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目