翻转一个链表
来源:互联网 发布:oracle数据库授权 编辑:程序博客网 时间:2024/06/05 05:41
给出一个链表1->2->3->null,这个翻转后的链表为3->2->1->null
public:
/**
* @param head: The first node of linked list.
* @return: The new head of reversed linked list.
*/
ListNode *reverse(ListNode *head) {
// write your code here
ListNode*p;
p=NULL;
while(head!=0) {
ListNode *aaa;
aaa=head->next;
head->next=p;
p=head;
head=aaa;
}
return p;
}
};
解题思路及感想:一开始把p标记为head,所以一直超出内存。
0 0
- 翻转一个链表
- 翻转一个链表
- 翻转一个链表
- 将一个链表翻转
- LintCode-翻转一个链表
- 递归地翻转一个链表
- 翻转一个单向链表的c语言代码
- 一个 while 实现 C 翻转单向链表
- 链表翻转:给出一个链表和一个数k,链表前k个节点进行翻转
- 翻转链表 给定一个链表个一个整数k 将从右边k个翻转到前边
- 无情链表的创建,,翻转翻转
- 链表翻转程序
- 链表翻转
- 链表翻转
- 链表翻转
- 翻转单向链表
- 翻转链表
- 原地翻转链表
- 69
- 队列
- 教程:Linux下安装JDK.
- 分享的资料收集
- C#解析Excel表
- 翻转一个链表
- 学习DS1820随记
- 【APIO2014】bzoj3676 回文串【解法二】
- LeetCode K-diff Pairs in an Array
- 阿里实习生测试一面(2017.3.29)
- 51nod 1067Bash游戏V2
- 接金币
- java环境变量的作用及如何配置
- CF 789E BFS