leetcode 206 Reverse Linked List
2016-06-23 22:39
411 查看
Reverse a singly linked list.
click to show more hints.
Subscribe to see which companies asked this question
click to show more hints.
Subscribe to see which companies asked this question
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *reverse(ListNode *head) { if(head == NULL) return head; ListNode *temp = reverse(head->next); head->next=NULL; if(temp!=NULL) temp->next = head; temp = head; return temp; } ListNode* reverseList(ListNode* head) { ListNode *temp = head; if(temp==NULL) return NULL; while(temp->next!=NULL) { temp = temp->next; } ListNode *res = reverse(head); return temp; } };
相关文章推荐
- 面试2
- 数字在排序数组中出现的次数
- 前端插件集合
- Python+Selenium进行UI自动化测试项目中,常用的小技巧4:日志打印,longging模块(控制台和文件同时输出)
- [android] android项目架构
- reactjs+echarts实现绘图
- 机器学习中的数据清洗与特征处理综述
- 手把手教你视频直播开发
- Eclipse Neon发布!
- java mail使用qq邮箱发邮件的配置方法
- leetcode 109 Convert Sorted List to Binary Search Tree
- github上传代码
- StringBuffer的capacity()方法
- Eclipse java swing 开发环境
- 问题 E: 交集
- JDBC代码
- Scrapy之日志文件的产生
- 远程过程调用RPC
- A星寻路
- 算法基础:排序与查找