c语言
潮起浪歌
学生
展开
-
21. 合并两个有序链表
struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2){ //l2作为被合链表,l1作为合入链表 if(l1==NULL) return l2; if(l2==NULL) return l1; struct ListNode *l1_q = l1, *l2_q = l2, *pre = NULL, *r;//工作指针q while(l1_q!=原创 2021-01-17 00:06:17 · 75 阅读 · 0 评论 -
234.回文链表
bool isPalindrome(struct ListNode* head){ if(head==NULL) return true; if(head->next==NULL) return true; //先求出链表长度 struct ListNode *p = head,*q = head,*q2,*r;//工作指针 int len = 0; while(p!=NULL) { len++;原创 2021-01-14 20:55:05 · 77 阅读 · 0 评论 -
203. 移除链表元素
莽子解法struct ListNode* removeElements(struct ListNode* head, int val){ struct ListNode *p,*pre,*s; if(head == NULL)//考虑特殊情况,空链表 { return NULL; } while((head != NULL)&&(head->val == val))//NULL->next会报错; &&am原创 2021-01-10 21:17:49 · 57 阅读 · 0 评论