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. 洛谷 P1120 小木棍[数据加强版]

    这道题可能是我做过的数据最不水的一道题-- 题目传送门 这题可以说是神剪枝,本身搜索并不算难,但剪枝是真不好想(好吧,我承认我看了题解)-- 剪枝: 用桶来存储木棍 在输入的时候记录下最长的木棍和最短 ...

  2. java在线聊天项目 使用SWT快速制作登录窗口,可视化窗口Design 更换窗口默认皮肤(切换Swing自带的几种皮肤如矩形带圆角)

    SWT成功激活后 new一个JDialog 调整到Design视图 默认的视图模式是BorderLayout,无论你怎么拖拽,只能放到东西南北中的位置上 所以,我们把视图模式调整为AbsoluteLa ...

  3. Java学习经验

    随着Java学习的深入,越来越感觉记笔记的重要性,一方面可以使自己更加善于总结,提高对项目和自己的认知,另一方面可以让知识条例更加鲜明,并且加深对知识点的记忆.Java是一门很早开始兴起的语言,用途非 ...

  4. 《offline coolbook》笔记

    https://jakearchibald.com/2014/offline-cookbook/ 在install中对依赖进行缓存 self.addEventListener('install', f ...

  5. 我的第一个ajax脚本

    代码如下 //创建XMLHttpRequest对象 var xmlHttp=null; function creatXMLHttp(){ try{ xmlHttp = new XMLHttpReque ...

  6. gg mirror

    https://gufen.ga/ (无广告,原guso.ml,ggso.ga,guge.ga) https://a.aiguso.tk (无广告,体验良好) https://a.freedo.gq/ ...

  7. jdbc 和 hibernate 比较

    相同点:都是数据库操作的中间件,都不是线程安全需要即时关闭,都可以对数据库操作进行显式处理. 不同:jdbc使用标准sql语言,hibernate使用HQL,操作对象jdbc直接操作数据传送到数据库, ...

  8. 浏览器在一次 HTTP 请求中,需要传输一个 4097 字节的文本数据给服务端,可以采用那些方式?

    浏览器在一次 HTTP 请求中,需要传输一个 4097 字节的文本数据给服务端,可以采用那些方式? 存入 IndexdDB 写入 COOKIE 放在 URL 参数 写入 Session 使用 POST ...

  9. 八、docker的常用命令

    1 Docker常用命令 1.1 存储镜像 如果要导出镜像到本地文件,可以使用 docker save 命令. docker save -o log_v140.tar docker.io/vmware ...

  10. div的显示隐藏方法汇总

    JQuery DIV 动态隐藏和显示的方法 1. 如果在载入是隐藏: <head> <script language="javascript"> funct ...