/**
* 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
if(pHead==NULL || pHead->next==NULL){
return pHead;
}
struct ListNode* p=NULL;
struct ListNode* q=pHead;
struct ListNode* cur=pHead->next;
while(cur){
q->next=p;
p=q;
q=cur;
cur=cur->next;
}
q->next=p;
return q;
}
牛客网链表反转解题代码
最新推荐文章于 2024-09-15 16:31:43 发布