What's the meaning of "in place"?


  • 0
    O

    hi all, I'm confused with the meaning of in place,is it saying do it without modifying the structure of the linked list?Is my code in-place?

    class Solution {
    public:
        ListNode *reverseBetween(ListNode *head, int m, int n)
        {
            n=n-m;
            ListNode *dummyhead=new ListNode(0);
            dummyhead->next=head;
            ListNode *pcur=dummyhead;
            while(--m>0) pcur=pcur->next;
            ListNode *pbm=pcur;
            pcur=pbm->next;
            while(n-->0)
            {
                ListNode* ptemp=pcur->next;
                pcur->next=ptemp->next;
                ptemp->next=pbm->next;
                pbm->next=ptemp;
            }
            return dummyhead->next;
        }
    };

  • 0
    R

    in place means do not use other functions. your solution is in-place.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.