day1 牛客网刷题
C语言实现单链表逆置
由于一段时间没有用数据结构 刚开始有些忘记了 第一次真正在牛客网上进行调试 原来还会有调试用例 还要设置边界值 如果没有 测试也不会通过
struct ListNode* ReverseList(struct ListNode* pHead ) {
// write code here
struct ListNode *temp;
struct ListNode *p=pHead->next;
if(pHead==NULL)
return 0;
if(pHead->next==NULL)
return pHead;
pHead->next=NULL;
while(p->next!=NULL){
temp=p->next;
p->next=pHead;
pHead=p;
p=temp;
}
p->next=pHead;
pHead=p;
return pHead;
}