leetcode 92

2018-12-25  本文已影响0人  Ariana不会哭
图片.png

C++:

ListNode* reverseBetween(ListNode* head, int m, int n) {
        ListNode* aa = new ListNode(-1);
        aa->next = head;
        ListNode* tt = aa;
        for (int i = 0; i < m - 1; i++) {
            tt = tt->next;
        }

        ListNode* start = tt->next;
        ListNode* end = tt->next;
        ListNode* t2 = start->next;
        for (int i = 0; i < n-m; i++) {
            ListNode* t3 = t2->next;
            t2->next = start;
            start = t2;
            t2 = t3;
        }
        tt->next = start;
        end->next = t2;
        return aa->next;
    }
上一篇下一篇

猜你喜欢

热点阅读