/**

  • struct ListNode {
  • int val;
  • struct ListNode *next;
  • };
  • C语言声明定义全局变量请加上static,防止重复定义
  • C语言声明定义全局变量请加上static,防止重复定义 */

/** *

  • @param pHead ListNode类

  • @return ListNode类 / struct ListNode ReverseList(struct ListNode* pHead ) { // write code here struct ListNode* ptrLast; struct ListNode* ptrTmp;

    if (NULL == pHead) { return pHead; }

    if (pHead->next != NULL) { ptrTmp = pHead; pHead = pHead->next; ptrTmp->next = NULL; ptrLast = ptrTmp;

     while (pHead->next != NULL)
     {
         ptrTmp = pHead;
         pHead = pHead->next;
         ptrTmp->next = ptrLast;
         ptrLast = ptrTmp;
     }
     
     pHead->next = ptrLast;
    

    }

    return pHead;
    }