// 先分析 拆成三段 16ms 过大的 1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution {10 public:11 ListNode *reverseBetween(ListNode *head, int m, int n) {12 // Start typing your C/C++ solution below13 // DO NOT write int main() function14 ListNode*preHead,*preEnd,*midHead,*midEnd,*r,*p,*q,*re;15 16 int i;17 18 19 preEnd=NULL;20 p=head;21 22 for(i=0;inext;26 }27 28 midEnd=p;29 30 q=NULL;31 32 for(i=0;i next;35 p->next=q;36 q=p;37 p=r;38 }39 40 if(preEnd==NULL)41 {42 re=q;43 }44 else45 {46 re=head;47 preEnd->next=q;48 }49 midEnd->next=r;50 51 return re;52 53 54 55 56 57 58 59 }60 61 62 };