【leetcode每日一题】NO206.Reverse Linked List
2015-08-13 10:13
387 查看
题目:Reverse a singly linked list.即单链表反序。
解析:链表反序是很常见的题目,不过多解释了,直接上代码。
解析:链表反序是很常见的题目,不过多解释了,直接上代码。
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* reverseList(ListNode* head) { if(head==NULL) return head; ListNode *curNode=head,*nextNode=head->next,*temp; while(nextNode!=NULL) { temp=nextNode->next; nextNode->next=curNode; curNode=nextNode; nextNode=temp; } head->next=NULL; head=curNode; return head; } };
相关文章推荐
- Android性能优化典范(二)
- gravity、layout_gravity及orientation
- UNIX网络编程卷一:第十六章 非阻塞I/O
- 类找不到问题追踪及分析
- sql的count()函数,php怎么取他的值
- Struts2动态方法调用
- RadioButton不能切换问题
- 从配置文件里读取配置信息
- 《招聘一个靠谱的iOS》面试题参考答案(上)
- 《android---获取值AndroidManifest.xml中meta-data的value》
- scp命令的实际应用
- 统计数n阶乘中0的位数
- SpringMVC基于代码的配置方式(零配置,无web.xml)
- 随机生成id,不会重复
- Android studio中正确引入so文件的方法
- overridePendingTransition的简介
- 扩展的验证工具类
- javascript高级程序设计知识整理(2)
- MT6753平台一项目不同手机最低亮度存偏差问题分析过程
- OpenPR开源代码项目(中科院自动化所)-含很多图像处理、模式识别、机器学习、自然语言处理的算法