[Leetcode]Reverse Linked List II

//将list存入vector。然后翻转中间部分数列
class Solution {
public:
    ListNode* reverseBetween(ListNode* head, int m, int n) {
        vector<ListNode*> node;
        ListNode* cur = head;
        for(int i=0;i<m-1;i++)
        cur=cur->next;
        for(int i=0;i<=n-m;i++)
        {
            node.push_back(cur);
            cur=cur->next;
        }
        for(int i=0;i<(n-m+1)/2;i++)
        swap(node[i]->val,node[node.size()-i-1]->val);
        return head;
    }
};
原文地址:https://www.cnblogs.com/lcchuguo/p/5197825.html