/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*
* C语言声明定义全局变量请加上static,防止重复定义
*/
/**
*
* @param pHead ListNode类
* @return ListNode类
*/
struct ListNode* ReverseList(struct ListNode* pHead ) {
if(pHead == NULL) return NULL;
if(pHead->next == NULL) return pHead;
struct ListNode *p1,*p2,*p;
p1 = pHead;
p2 = p1->next;
p1->next = NULL;
while(p2->next != NULL)
{
p = p2->next;
p2->next = p1;
p1 = p2;
p2 = p;
}
p2->next = p1;
pHead = p2;
return pHead;
}
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*
* C语言声明定义全局变量请加上static,防止重复定义
*/
/**
*
* @param pHead ListNode类
* @return ListNode类
*/
struct ListNode* ReverseList(struct ListNode* pHead ) {
if(pHead == NULL) return NULL;
if(pHead->next == NULL) return pHead;
struct ListNode *p1,*p2,*p;
p1 = pHead;
p2 = p1->next;
p1->next = NULL;
while(p2->next != NULL)
{
p = p2->next;
p2->next = p1;
p1 = p2;
p2 = p;
}
p2->next = p1;
pHead = p2;
return pHead;
}