My C progrm easy to Understand


  • 1
    S

    class Solution {

    public:

    ListNode* reverseList(ListNode* head) {
        ListNode * cur= head;
        ListNode * tempt=NULL;
        if (head==NULL||head->next==NULL){
            return head;
        }
        
        while (cur->next!=NULL&& cur!=NULL){
            tempt=cur->next;
            cur->next=tempt->next;
            tempt->next=head;
            head=tempt;
            tempt=cur->next;
        }
        return head;
    }
    

    };


Log in to reply
 

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