LintCode-剑指Offer-翻转链表
来源:互联网 发布:cf免费刷军衔软件 编辑:程序博客网 时间:2024/06/11 16:56
/**
* Definition of ListNode
*
* class ListNode {
* public:
* int val;
* ListNode *next;
*
* ListNode(int val) {
* this->val = val;
* this->next = NULL;
* }
* }
*/
class Solution {
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
if(head==NULL||head->next==NULL)
return head;
ListNode* r=new ListNode(0);
ListNode* tmp=r;
ListNode* tmp2=NULL;
while(tmp!=NULL){
tmp=head->next;
head->next=r->next;
r->next=head;
head=tmp;
}
return r->next;
}
};
* Definition of ListNode
*
* class ListNode {
* public:
* int val;
* ListNode *next;
*
* ListNode(int val) {
* this->val = val;
* this->next = NULL;
* }
* }
*/
class Solution {
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
if(head==NULL||head->next==NULL)
return head;
ListNode* r=new ListNode(0);
ListNode* tmp=r;
ListNode* tmp2=NULL;
while(tmp!=NULL){
tmp=head->next;
head->next=r->next;
r->next=head;
head=tmp;
}
return r->next;
}
};
0 0
- LintCode-剑指Offer-翻转链表
- LintCode-剑指Offer-(53)翻转字符串
- LintCode-翻转链表
- lintcode 翻转链表
- LintCode:翻转链表
- lintcode,翻转链表
- 翻转链表,lintcode
- Lintcode 翻转链表
- LintCode 翻转链表
- 翻转链表-LintCode
- LintCode : 翻转链表
- [Lintcode]翻转链表
- lintcode--翻转链表
- Lintcode翻转链表
- LintCode 翻转链表
- lintcode翻转链表
- LintCode 翻转链表
- Lintcode:翻转链表
- java中用builder模式实现实体类的创建
- R语言对地形数据进行三维可视化
- Web Service 那点事儿(3)—— SOAP 及其安全控制
- 软件工程学习日记(4)----面向数据流的设计方法
- 聚类经典方法K-means及其变种
- LintCode-剑指Offer-翻转链表
- [ecshop 资料] ecshop 会员增加字段 msn地址不是一个有效的邮件地址 68ecshop
- Linux下线程的调度策略与优先级(二) http://blog.csdn.net/dongliqiang2006/article/details/5837828
- Equatable
- Python神图
- Linux下线程的调度策略与优先级(一) http://blog.csdn.net/dongliqiang2006/article/details/5837824
- Javascript常见的用户信息输入校验
- CS5汉化步骤
- su root 和 su - root 区别