lc92+Reverse Linked List II

https://leetcode.com/problems/reverse-linked-list-ii/

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* new_head=new ListNode(0);
        new_head->next=head;
        ListNode* pre=new_head;
        for(int i=0;inext;
        }
        ListNode* cur=pre->next;
        for(int i=0;inext;
            cur->next=move->next;
            move->next=pre->next;
            pre->next=move;
        }
        return new_head->next;
    }
};

 

你可能感兴趣的:(进阶LC)