# [leetcode] 【链表】92. 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->2->3->4->5->NULLm = 2 and n = 4,

return 1->4->3->2->5->NULL.

Note:
Given mn satisfy the following condition:

1 ≤ m ≤ n ≤ length of list.

# 题解

/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* reverseBetween(ListNode* head, int m, int n) {
for(int i=0;i<m-1;i++)
prev=prev->next;
ListNode *cur=prev->next;
for(int i=0;i<n-m;i++)
{
prev->next=cur->next;
cur=prev->next;
}
}
};

• 本文已收录于以下专栏：

## [LeetCode-92] Reverse Linked List II（反转指定区间链表）

【分析】反转链表，但不是从头到尾的反转，给定了一个[m,n]范围，反转指定区间的链表。1 ≤ m ≤ n ≤ length of list.不满足条件的话，返回原链表

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

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

## [Leetcode]#92 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->2-...

## LeetCode 92. Reverse Linked List II

1. 题目描述 Reverse a linked list from position m to n. Do it in-place and in one-pass. For examp...

## leetcode No92. Reverse Linked List II

Question: Reverse a linked list from position m to n. Do it in-place and in one-pass. For exam...

## LeetCode 92. Reverse Linked List II ***** 虚拟头结点

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)