leetcode 反转链表

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* reverseList(struct ListNode* head) {
  
   
    if(head==NULL)
        return NULL;
        
     struct ListNode*prev=NULL;
     
    while(head!=NULL)
    {
        struct ListNode *temp;
        temp = head->next;
        head->next = prev;
        prev = head;
        head = temp;
    }
    return prev;
    
}

 

你可能感兴趣的:(LeetCode)