C solution.(use for loop)


  • 0
    N
    struct ListNode* reverseList(struct ListNode* head) {
        struct ListNode *tmp=NULL,*ptr=NULL;
        if(head!=NULL){
            for(ptr=head;ptr->next!=NULL;ptr=head){
                head=ptr->next;
                ptr->next=tmp;
                tmp=ptr;
            }
            ptr->next=tmp;
        }
    return head;
    }
    

Log in to reply
 

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