这题用需要非常细心,用头插法移动需要考虑先移动哪个,只需三个指针即可。

ListNode *reverseList(ListNode *head, int m, int n)
{
ListNode dummy(-);
dummy.next = head;
ListNode *prev = &dummy; for (int i = ; i < m - ; i++)
prev = prev->next;//要调整的数之前的那个数 ListNode *head2 = prev;
prev = head2->next;
ListNode *curr = prev->next;
for (int i = m; i < n; i++)
{
prev->next = curr->next;//头插法
curr->next = head2->next;
head2->next = curr; curr = prev->next;
}
}

leetcode 之Reverse Linked List II(15)的更多相关文章

  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 (middle)

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

  7. 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-> ...

  8. 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-> ...

  9. 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. BZOJ3052 & UOJ58:[WC2013]糖果公园——题解

    http://uoj.ac/problem/58 http://www.lydsy.com/JudgeOnline/problem.php?id=3052 输入格式 输出格式 input 4 3 5 ...

  2. BZOJ1857:[SCOI2010]传送带——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1857 Description 在一个2维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送 ...

  3. HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)

    HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...

  4. scanf函数用法小记

    By francis_hao    Aug 26,2017   scanf – 输入格式转换   概述 #include <stdio.h>int scanf(const char *fo ...

  5. UVA796:Critical Links(输出桥)

    Critical Links 题目链接:https://vjudge.net/problem/UVA-796 Description: In a computer network a link L, ...

  6. C. Line (扩展欧几里得)

    C. Line time limit per test 1 second memory limit per test 256 megabytes input standard input output ...

  7. bzoj 相似回文串 3350 3103 弦图染色+manacher

    相似回文串 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 143  Solved: 68[Submit][Status][Discuss] Descr ...

  8. [Leetcode] LRU 算法实现

    Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...

  9. 2015/9/17 Python基础(13):函数

    函数是对程序逻辑进行结构化或过程化的一种编程方法. Python的函数返回值当什么也不返回时,返回了None和大多数语言一样,Python返回一个值或对象.只是在返回容器对象时,看起来像返回多个对象. ...

  10. 初识Webx 1

    Webx是一套基于Java Servlet API的通用Web框架.它在Alibaba集团内部被广泛使用.从2010年底,向社会开放源码. Webx框架是一个稳定.强大的Web框架.建立在Spring ...