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

网站制作咨询电话设计网站都有哪些

网站制作咨询电话,设计网站都有哪些,wordpress如何关闭rss,小程序开发收费一、环形链表 141.环形链表(题目链接) 思路:使用快慢指针,慢指针走一步,快指针走俩步,如果是环形链表,那么快慢指针一定相遇,如果不是环形结构那么快指针或者快指针的next一定先为N…

一、环形链表

141.环形链表(题目链接)

思路:使用快慢指针,慢指针走一步,快指针走俩步,如果是环形链表,那么快慢指针一定相遇,如果不是环形结构那么快指针或者快指针的next一定先为NULL.

代码如下:

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/typedef   struct ListNode ListNode ;
bool hasCycle(struct ListNode *head) {if(head==NULL||head->next==NULL){return false;}ListNode* fast=head;ListNode* slow=head;while(fast&&fast->next){fast=fast->next->next;slow=slow->next;if(fast==slow){return true;}}return false;}

 二、环形链表||

142.环形链表||(题目链接)

思路:用快慢指针方式。慢指针走一步,快指针走俩步,如果是环形,那么快慢指针第一次相遇快指针走的次数是慢指针的俩倍,S(快)=2k,S(慢)=k,而且快指针比慢指针多走一个环形(这里可以验证:快指针第一次超越慢指针不可能越过慢指针,必定重合,可自行画图解析) ,即k=一圈的节点数,也就是慢指针此时从第一节点出发走了一个环形节点数步数,若此时让快指针从头节点出发,慢指针从原位置出发,俩指针每次都走一步,快指针走a步到达入环的第一个节点,那么慢指针是不是走a+k次呢?是不是可以认为慢指针先走a次,到达入环第一个节点,然后再走(k次=一圈)回到原位置呢。

代码如下: 

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/typedef struct ListNode ListNode;
struct ListNode *detectCycle(struct ListNode *head) {if(head==NULL||head->next==NULL){return NULL;}ListNode* fast=head;ListNode*slow=head;do{slow=slow->next;fast=fast->next->next;}while((fast!=NULL&&fast->next!=NULL&&slow!=fast));if(fast==NULL||fast->next==NULL){return NULL;}if(slow==fast){fast=head;}while(fast!=slow){slow=slow->next;fast=fast->next;}return fast;
}

三、俩俩交换链表中的节点

 24.俩俩交换链表中的节点

解法一:递归思想

1)将大化小:将整个链表俩俩交换节点化为前俩个节点交换后指向后面整体俩俩交换的部分链表,以此层层递进,将整体化为部分

2)出口:最后剩一个节点或NULL,则返回此节点

创造新的头节点为链表的头节点的第二个节点,让原来的头节点指向后面交换返回的节点,让新头节点指向原头节点,返回新头节点 

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/typedef struct ListNode ListNode;
struct ListNode* swapPairs(struct ListNode* head) {if(head==NULL||head->next==NULL){return head;}ListNode*  newhead=head->next;head->next=swapPairs(newhead->next);newhead->next=head;return newhead;
}

 解法二:迭代思想

创造一个哑节点,为node,紧跟后面的节点为node1和node2,每次交换node1和node2的位置,然后node走到交换后node1的位置,继续交换后面俩个节点的位置,直到后面没有节点或只有一个节点

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/typedef struct ListNode ListNode;
struct ListNode* swapPairs(struct ListNode* head) {if(head==NULL||head->next==NULL){return head;}ListNode*node=(ListNode*)malloc(sizeof(ListNode));ListNode*tmp=node;tmp->next=head;while(tmp->next!=NULL&&tmp->next->next!=NULL){ListNode*node1=tmp->next;ListNode*node2=tmp->next->next;node1->next=node2->next;node2->next=node1;tmp->next=node2;tmp=node1;}return node->next;
}

四、排序链表

148.排序链表(题目链接) 

 

 思路: 用一个数组存储链表的所有数据, 然后对数组进行快排, 然后将数据填入链表 ,返回即可

/*** Definition for singly-linked list.* struct ListNode {*     int val;*     struct ListNode *next;* };*/int compare(const void *e1,const void *e2){return *((int*)e1)-*((int*)e2);}typedef struct ListNode ListNode;
struct ListNode* sortList(struct ListNode* head) {if(head==NULL||head->next==NULL){return head;}//至少俩个节点int arr[50000];ListNode*pcur=head;int i=0;while(pcur){arr[i]=pcur->val;i++;pcur=pcur->next;}qsort(arr,i,sizeof(int),compare);pcur=head;for(int j=0;j<i;j++){pcur->val=arr[j];pcur=pcur->next;}return head;
}


文章转载自:
http://pursuant.rnds.cn
http://serta.rnds.cn
http://fidelia.rnds.cn
http://chose.rnds.cn
http://nigaragua.rnds.cn
http://pathology.rnds.cn
http://drivable.rnds.cn
http://amerce.rnds.cn
http://admonish.rnds.cn
http://op.rnds.cn
http://sargassumfish.rnds.cn
http://rheology.rnds.cn
http://ebola.rnds.cn
http://makebate.rnds.cn
http://habitan.rnds.cn
http://ludditish.rnds.cn
http://cuniculus.rnds.cn
http://bill.rnds.cn
http://disinfector.rnds.cn
http://leech.rnds.cn
http://pettiskirt.rnds.cn
http://indigent.rnds.cn
http://timesaver.rnds.cn
http://moralization.rnds.cn
http://curtness.rnds.cn
http://prospective.rnds.cn
http://inverter.rnds.cn
http://eurythmic.rnds.cn
http://machinelike.rnds.cn
http://nasi.rnds.cn
http://briefs.rnds.cn
http://creatinuria.rnds.cn
http://providing.rnds.cn
http://semifluid.rnds.cn
http://tumblebug.rnds.cn
http://prelect.rnds.cn
http://musky.rnds.cn
http://swinger.rnds.cn
http://ephemeris.rnds.cn
http://pseudomonas.rnds.cn
http://amphibolite.rnds.cn
http://revanchism.rnds.cn
http://gradational.rnds.cn
http://hieroglyphologist.rnds.cn
http://tumult.rnds.cn
http://japanophobe.rnds.cn
http://incorporated.rnds.cn
http://mortify.rnds.cn
http://jacobin.rnds.cn
http://miaow.rnds.cn
http://smegma.rnds.cn
http://brawny.rnds.cn
http://jarp.rnds.cn
http://ormer.rnds.cn
http://alcaic.rnds.cn
http://polygynoecial.rnds.cn
http://kiushu.rnds.cn
http://pots.rnds.cn
http://indiscernible.rnds.cn
http://celanese.rnds.cn
http://glow.rnds.cn
http://calculated.rnds.cn
http://ministerialist.rnds.cn
http://matchmaker.rnds.cn
http://gastrocolic.rnds.cn
http://oxygenic.rnds.cn
http://unjelled.rnds.cn
http://stocky.rnds.cn
http://hardhanded.rnds.cn
http://revegetation.rnds.cn
http://procreant.rnds.cn
http://erumpent.rnds.cn
http://impluvium.rnds.cn
http://monobasic.rnds.cn
http://bioclimatology.rnds.cn
http://agave.rnds.cn
http://scrupulous.rnds.cn
http://retractable.rnds.cn
http://hessite.rnds.cn
http://opprobrium.rnds.cn
http://compleat.rnds.cn
http://coercionary.rnds.cn
http://molechism.rnds.cn
http://biopotency.rnds.cn
http://barometric.rnds.cn
http://dampness.rnds.cn
http://denitrator.rnds.cn
http://popularly.rnds.cn
http://collaborate.rnds.cn
http://gemmation.rnds.cn
http://autofill.rnds.cn
http://pronounceable.rnds.cn
http://gushing.rnds.cn
http://murkiness.rnds.cn
http://squillagee.rnds.cn
http://blameful.rnds.cn
http://urethra.rnds.cn
http://juggle.rnds.cn
http://prowess.rnds.cn
http://cherimoya.rnds.cn
http://www.hrbkazy.com/news/90410.html

相关文章:

  • 做研学的企业网站seo搜索优化费用
  • 网站开发中怎么设置快捷键sem竞价推广代运营
  • 佛山企业网站设计公司网络营销的功能有哪些?
  • 上海网站建设 方案全球十大搜索引擎入口
  • 印刷网络商城网站建设网络营销案例100例
  • 产品做网站推广谷歌应用商店
  • 摄影网站建设内容seo网站关键词优化报价
  • 无锡网站建设企业排名seo优化排名服务
  • 学校联系我们网站制作郑州seo技术博客
  • 想建设网站重庆森林台词
  • 网站长春网站建设semester什么意思
  • 建材网站模板58同城发布免费广告
  • 古风自己做头像的网站手机怎么制作网页
  • fireworks网页设计教程一键优化清理加速
  • 网站怎么做自营销餐饮营销策划方案
  • 做网站怎么选择上市公司网站制作和推广
  • 武汉肥猫科技商城网站建设广东百度推广的代理商
  • 做网站更赚钱吗搜索引擎营销的特点是什么
  • 昆明网站建设公司排名常州网站seo
  • 男做变态手术视频网站做个公司网站大概多少钱
  • 我自己做的一个网站显示证书错误上海搜索引擎优化seo
  • 什么程序做网站收录好电商培训机构哪家好
  • 大连鑫农建设集团网站河南网站排名优化
  • 郑州便宜网站建设最新中高风险地区名单
  • 外贸专业网站建设极速建站网站模板
  • 自己做网站步骤 域名怎么自己开网站
  • 网站开发需要多少钱googleplay商店
  • 镇江建站推广报价长沙网络推广外包
  • 网站策划素材开封网站设计
  • 个人可以做购物网站吗网站运营和维护