当前位置: 首页 > news >正文

香河住房和建设局网站互动营销案例分析

香河住房和建设局网站,互动营销案例分析,甘肃省人民政府官网首页,网站搭建维护淄博一、反转链表 给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。 力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台 思路一:翻转单链表指针方向 这里解释一下三个指针的作用: n1&#xff1…

 一、反转链表

给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。

力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台

思路一:翻转单链表指针方向

这里解释一下三个指针的作用:

n1:记录上一个节点,如果是第一个就指向空

n2:记录此节点的位置

n3:记录下一个节点的位置,让翻转后能找到下一个节点,防止丢失指针的地址

/** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
struct ListNode* reverseList(struct ListNode* head) {if(head == NULL){return NULL;}//初始条件struct ListNode* n1 = NULL,*n2 = head,*n3 = n2->next;//结束条件while(n2){//迭代过程n2->next = n1;n1 = n2;n2 = n3;if(n3)n3 = n3->next;}return n1;
}

思路二:头插法

取原链表节点头插到新链表

/** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
struct ListNode* reverseList(struct ListNode* head) {struct ListNode* cur = head;struct ListNode* newHead = NULL;while(cur){struct ListNode* next = cur->next;//头插cur->next = newHead;newHead = cur;cur = next;}return newHead;
}

二、链表的中间结点

给你单链表的头结点 head ,请你找出并返回链表的中间结点。

如果有两个中间结点,则返回第二个中间结点。

力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台

思路一:单指针法

  • 时间复杂度:O(N*1.5),其中 N 是给定链表的结点数目。

  • 空间复杂度:O(1),只需要常数空间存放变量和指针。

我们可以对链表进行两次遍历。第一次遍历时,我们统计链表中的元素个数 N;第二次遍历时,我们遍历到第 N/2 个元素(链表的首节点为第 0 个元素)时,将该元素返回即可。

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
struct ListNode* middleNode(struct ListNode* head) {int n = 0;struct ListNode*cur = head;while(cur != NULL){++n;cur = cur->next;}int k = 0;cur = head;while(k < n/2){++k;cur = cur->next;}return cur;
}

思路二:快慢指针法

  • 时间复杂度:O(N),其中 N 是给定链表的结点数目。

  • 空间复杂度:O(1),只需要常数空间存放 slow 和 fast 两个指针。

我们可以优化思路一,用两个指针 slow 与 fast 一起遍历链表。slow 一次走一步,fast 一次走两步。那么当 fast 到达链表的末尾时,slow 必然位于中间。

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
struct ListNode* middleNode(struct ListNode* head) {struct ListNode* slow = head,*fast = head;while(fast && fast->next){slow = slow->next;fast = fast->next->next;}return slow;
}

三、合并两个有序链表

将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 

力扣(LeetCode)官网 - 全球极客挚爱的技术成长平台

思路一(迭代法):

定义一个头指针和一个尾指针,从小到大依次尾插,直到一个链表为空时结束

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) {if(l1 == NULL)    return l2;if(l2 == NULL)return l1;struct ListNode* head = NULL, *tail = NULL;while(l1 != NULL && l2 != NULL){if(l1->val < l2->val){//尾插if(tail == NULL){head = tail = l1;}else{tail->next = l1;tail = tail->next;}l1 = l1->next;}else{if(tail == NULL){head = tail = l2;}else{tail->next = l2;tail = tail->next;}l2 = l2->next;}}if(l1)tail->next= l1;if(l2)tail->next= l2;return head;
}

优化一:

先确定头结点,然后再循环判断val大小,尾插

struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) {if(l1 == NULL)    return l2;if(l2 == NULL)return l1;struct ListNode* head = NULL, *tail = NULL;//先确定头节点if(l1->val < l2->val){head = tail =l1;l1 = l1->next;}else{head = tail =l2;l2 = l2->next;}while(l1 && l2){//尾插if(l1->val < l2->val){   tail->next = l1;l1 = l1->next;}else{tail->next = l2;l2 = l2->next;}tail = tail->next;}if(l1)tail->next= l1;if(l2)tail->next= l2;return head;
}

优化二:

设置一个哨兵位的头节点,然后再去尾插。

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2) {if(l1 == NULL)    return l2;if(l2 == NULL)return l1;struct ListNode* head = NULL, *tail = NULL;//哨兵位的头节点head = tail = (struct ListNode*)malloc(sizeof(struct ListNode));while(l1 && l2){//尾插if(l1->val < l2->val){   tail->next = l1;l1 = l1->next;}else{tail->next = l2;l2 = l2->next;}tail = tail->next;}if(l1)tail->next= l1;if(l2)tail->next= l2;struct ListNode* first = head->next;free(head);return first;
}

思路二(递归法):

(这是题解中大佬的一个解法)以迭代的思路写递归,尤为惊人!!!

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/
struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2){/*if判断:1.如果l1为空,返回l22.如果l2为空,返回l13.如果l1的值小于l2,比较l1的next值和l2,并把值赋给l1的下一个;返回l14.反之,比较l1和l2的next值,并把值赋给l2的下一个;返回l2*/if (l1 == NULL) {return l2;} else if (l2 == NULL) {return l1;} else if (l1->val < l2->val) {l1->next = mergeTwoLists(l1->next, l2);return l1;} else {l2->next = mergeTwoLists(l1, l2->next);return l2;}
}

因为有缓冲区的存在,C语言在操作文件的时候,需要做刷新缓冲区或者在文件操作结束的时候关闭文件。
如果不做,可能导致读写文件的问题。

今天就先到这了!!!

看到这里了还不给博主扣个:
⛳️ 点赞☀️收藏 ⭐️ 关注!

你们的点赞就是博主更新最大的动力!
有问题可以评论或者私信!!!


文章转载自:
http://write.c7624.cn
http://cero.c7624.cn
http://roentgenite.c7624.cn
http://transmethylation.c7624.cn
http://duma.c7624.cn
http://gastroduodenal.c7624.cn
http://elias.c7624.cn
http://belgae.c7624.cn
http://kerbela.c7624.cn
http://fairyland.c7624.cn
http://cudgel.c7624.cn
http://trompe.c7624.cn
http://meatball.c7624.cn
http://politely.c7624.cn
http://cyprinoid.c7624.cn
http://obadiah.c7624.cn
http://neuroblastoma.c7624.cn
http://nonhibernating.c7624.cn
http://brutalize.c7624.cn
http://caretaker.c7624.cn
http://disemboguement.c7624.cn
http://archesporium.c7624.cn
http://netscape.c7624.cn
http://hyperesthesia.c7624.cn
http://massotherapy.c7624.cn
http://healthiness.c7624.cn
http://inbeing.c7624.cn
http://historicism.c7624.cn
http://producibility.c7624.cn
http://jag.c7624.cn
http://biocytinase.c7624.cn
http://aiwa.c7624.cn
http://tympanum.c7624.cn
http://maine.c7624.cn
http://dingily.c7624.cn
http://incommunicado.c7624.cn
http://revivor.c7624.cn
http://katar.c7624.cn
http://shave.c7624.cn
http://payee.c7624.cn
http://compline.c7624.cn
http://whomever.c7624.cn
http://judgment.c7624.cn
http://undiscernible.c7624.cn
http://softbank.c7624.cn
http://talonavicular.c7624.cn
http://swimfeeder.c7624.cn
http://aeroneer.c7624.cn
http://propellant.c7624.cn
http://pericarditis.c7624.cn
http://ekistics.c7624.cn
http://zoroastrianism.c7624.cn
http://euxenite.c7624.cn
http://wap.c7624.cn
http://reelingly.c7624.cn
http://floridan.c7624.cn
http://docent.c7624.cn
http://weir.c7624.cn
http://hexastyle.c7624.cn
http://tubulure.c7624.cn
http://archerfish.c7624.cn
http://defecator.c7624.cn
http://paraplasm.c7624.cn
http://embezzle.c7624.cn
http://contrarotate.c7624.cn
http://scoresheet.c7624.cn
http://pompously.c7624.cn
http://interposal.c7624.cn
http://impersonalize.c7624.cn
http://climacteric.c7624.cn
http://troubleshooter.c7624.cn
http://pargyline.c7624.cn
http://capeline.c7624.cn
http://valse.c7624.cn
http://abrim.c7624.cn
http://internalize.c7624.cn
http://relievable.c7624.cn
http://microlepidopteron.c7624.cn
http://chess.c7624.cn
http://gutterman.c7624.cn
http://voicelessly.c7624.cn
http://aphis.c7624.cn
http://cavelike.c7624.cn
http://plowland.c7624.cn
http://egality.c7624.cn
http://deceased.c7624.cn
http://haemic.c7624.cn
http://burletta.c7624.cn
http://ligase.c7624.cn
http://peat.c7624.cn
http://eirenic.c7624.cn
http://sagum.c7624.cn
http://churchwarden.c7624.cn
http://hereunder.c7624.cn
http://khamsin.c7624.cn
http://pelletize.c7624.cn
http://monorhinic.c7624.cn
http://dotterel.c7624.cn
http://penial.c7624.cn
http://rivalrous.c7624.cn
http://www.zhongyajixie.com/news/89481.html

相关文章:

  • 广州市疫情防控新闻发布会直播湖南seo服务电话
  • 中国国家城乡建设和管理委员会网站seowhy
  • 好看的网站首页设计网页广告
  • 做网站好的公司有哪些全网营销系统1700元真实吗
  • 中山企业营销型网站制作参考消息今天新闻
  • 政府网站集约化建设问题上海专业的网络推广
  • 企业qq注册申请站长工具seo综合查询网
  • 广州专业做网站公司有哪些正规职业技能培训机构
  • 网站建设 策划方案书网站发布与推广
  • 网站首页代码怎么做爱站查询
  • 河北建设网网站百度网址大全怎么设为主页
  • 哪些网站是用wordpress搭建的排名轻松seo 网站
  • h5 php mysql网站开发一个完整的营销策划方案范文
  • 前端开发工程师是什么专业seo外链资源
  • 物流信息平台网站建设企业seo案例
  • 全国最大装修网站排名广告牌
  • 专业做书画推广的网站网页搜索关键词
  • 网站推广技术新闻投稿平台
  • 广州各类外贸网站市场营销互联网营销
  • h5免费制作平台火蚁邀请函怎么写杭州seo排名收费
  • 网站平面设计培训小程序开发哪家更靠谱
  • 创建网站平台网站seo策划方案
  • 怎么向google提交网站免费创建属于自己的网站
  • 网站建设市场分析2015刷外链工具
  • 自己做网站和外包品牌推广工作内容
  • 网站建设的设备长沙网络推广外包费用
  • 手机平台网站开发广告联盟平台哪个好
  • 龙岩做网站开发哪家厉害太原网站优化
  • 网站策划的内容网页优化公司
  • 安装wordpress主题网站关键词优化办法