Time Limit exceeded : Help


  • 0
    S

    class Solution {
    public:
    ListNode* reverseList(ListNode* head) {
    if(head==NULL)
    return head;
    if(head->next==NULL)
    return head;
    ListNode* prev = head;
    ListNode* pres = prev->next;
    ListNode* next = pres->next;
    while(next!= NULL) {
    pres->next = prev;
    prev= pres;
    pres= next;
    next = next->next;
    }
    pres->next= prev;
    head = pres;
    return head;
    }
    };


Log in to reply
 

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