http://oj.leetcode.com/problems/reverse-linked-list-ii/

链表的操作

#include <iostream>
using namespace std; struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
}; class Solution {
public:
ListNode *reverseBetween(ListNode *head, int m, int n) {
ListNode dummy(-);
dummy.next = head; ListNode *prev = &dummy;
for(int i = ;i<m-;++i)
{
prev = prev->next;
}
ListNode* const head2 = prev; prev = head2->next;
ListNode *cur = prev->next;
for(int i = m;i<n;++i)
{
prev->next = cur->next;
cur->next = head2->next;
head2->next = cur;
cur = prev->next;
}
return dummy.next;
}
}; int main()
{
ListNode *n1 = new ListNode();
ListNode *n2 = new ListNode();
ListNode *n3 = new ListNode();
ListNode *n4 = new ListNode();
ListNode *n5 = new ListNode();
n1->next = n2;
n2->next = n3;
n3->next = n4;
n4->next = n5;
ListNode *ans;
Solution myS;
ans = myS.reverseBetween(n1,,);
return ;
}

LeetCode OJ--Reverse Linked List II的更多相关文章

  1. 【leetcode】Reverse Linked List II

    Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one-pass. F ...

  2. leetcode -day30 Reverse Linked List II

    1.  Reverse Linked List II  Reverse a linked list from position m to n. Do it in-place and in one- ...

  3. [LeetCode] 92. Reverse Linked List II 反向链表II

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...

  4. Java for LeetCode 092 Reverse Linked List II

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1-> ...

  5. [LeetCode] 92. Reverse Linked List II 倒置链表之二

    Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Exa ...

  6. leetcode 【 Reverse Linked List II 】 python 实现

    题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1- ...

  7. 【leetcode】Reverse Linked List II (middle)

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...

  8. leetcode 92 Reverse Linked List II ----- java

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...

  9. leetcode:Reverse Linked List II

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...

  10. LeetCode 92. Reverse Linked List II倒置链表2 C++

    Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Exa ...

随机推荐

  1. 第五次作业:Excel制作英文课程表

    要求: 一.内外变宽线条与颜色图同,表格有底纹色彩 二.横向打印,上下左右居中,表格标题居中,表头斜线,斜线两边加文字 三.设置打开密码

  2. 微信小程序canvas实现圆形计时器功能

    index.js import Canvas from '../../utils/canvas.js'Page({ ...Canvas.options, /** * 页面的初始数据 */ data: ...

  3. (57)zabbix Slide shows幻灯片展示

    定义好screen之后,我们想了解服务器状况之时,一般会一个个screen点过去,zabbix提供了幻灯片展示方法,可以定义多个Slide,一个slide中可以包含多个screen. 创建slide ...

  4. 怎么用js写一个类似于百度输入框的搜索插件

    PS:这次做的这个小插件只是在前端实现,并没有经过数据库.需要用到的的框架:1.bootstrap.css的样式 2.Vue.js 最终效果如下: JS部分: $(window).click(func ...

  5. mysql:explain分析sql

    对于执行较慢的sql,可以使用explain命令查看这些sql的执行计划.查看该SQL语句有没有使用上了索引,有没有做全表扫描,这都可以通过explain命令来查看 mysql> explain ...

  6. Python的两个爬虫框架PySpider与Scrapy安装

    Python的两个爬虫框架PySpider与Scrapy安装 win10安装pyspider: 最好以管理员身份运行CMD,不然可能会出现拒绝访问文件夹的情况! pyspider:pip instal ...

  7. Aizu-ALDS1_3_A:Stack

    D - Stack Write a program which reads an expression in the Reverse Polish notation and prints the co ...

  8. Ubuntu 16.04 LTS上git提交出现警告Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts. 的解决方法

    问题: Ubuntu 16.04 LTS执行 git pull时总会出现以下警告: Warning: Permanently added 'github.com,52.74.223.119' (RSA ...

  9. linux 下常见命令

    ===============安装和登陆命令============================================================= Mount: 挂载命令.把存储介 ...

  10. Redis 数据类型分析 字符串 哈希 列表 集合 有序集合 优缺点 分析 注意事项 存储结构

    一.提高Redis使用性能秘诀 KEY尽量少的原则,能放在1个KEY的就放入1个KEY,KEY开销很大尽量减少与Redis发生的交互次数,能批量的就批量,能事务.管道的就事务.管道从业务架构分析确定使 ...