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

网站后台模板关联自己做的网站网络营销与直播电商专业

网站后台模板关联自己做的网站,网络营销与直播电商专业,虚拟机怎么做网页,企业网站开发公司大全一、环形链表 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://aphrodite.c7624.cn
http://bonnily.c7624.cn
http://counterfactual.c7624.cn
http://fifty.c7624.cn
http://preaxial.c7624.cn
http://inscrutable.c7624.cn
http://aborative.c7624.cn
http://nevada.c7624.cn
http://raucously.c7624.cn
http://lampadephoria.c7624.cn
http://taiyuan.c7624.cn
http://comate.c7624.cn
http://occult.c7624.cn
http://pantywaist.c7624.cn
http://clef.c7624.cn
http://subhumid.c7624.cn
http://crusher.c7624.cn
http://oreology.c7624.cn
http://gehenna.c7624.cn
http://luteinization.c7624.cn
http://boreen.c7624.cn
http://passkey.c7624.cn
http://bookwork.c7624.cn
http://segment.c7624.cn
http://halfbeak.c7624.cn
http://jimjams.c7624.cn
http://ranid.c7624.cn
http://backed.c7624.cn
http://admission.c7624.cn
http://alluvion.c7624.cn
http://grassy.c7624.cn
http://prattler.c7624.cn
http://panicky.c7624.cn
http://skyless.c7624.cn
http://metatarsus.c7624.cn
http://actinolite.c7624.cn
http://thee.c7624.cn
http://pejorative.c7624.cn
http://modernday.c7624.cn
http://estafette.c7624.cn
http://subjunction.c7624.cn
http://birdy.c7624.cn
http://vitalist.c7624.cn
http://ek.c7624.cn
http://stalinist.c7624.cn
http://idealistic.c7624.cn
http://mythoheroic.c7624.cn
http://babirusa.c7624.cn
http://drawnet.c7624.cn
http://letterform.c7624.cn
http://kanpur.c7624.cn
http://nonfood.c7624.cn
http://punishable.c7624.cn
http://cundum.c7624.cn
http://mammillate.c7624.cn
http://dysphasic.c7624.cn
http://hemogram.c7624.cn
http://provisionally.c7624.cn
http://reporter.c7624.cn
http://endocast.c7624.cn
http://collegia.c7624.cn
http://discourteous.c7624.cn
http://rachitic.c7624.cn
http://malocclusion.c7624.cn
http://weazand.c7624.cn
http://perigee.c7624.cn
http://lollingite.c7624.cn
http://squadsman.c7624.cn
http://termitary.c7624.cn
http://refinedly.c7624.cn
http://meadowsweet.c7624.cn
http://kneecapping.c7624.cn
http://lionmask.c7624.cn
http://domesticable.c7624.cn
http://drawnwork.c7624.cn
http://loudly.c7624.cn
http://botryoid.c7624.cn
http://kaunas.c7624.cn
http://inhere.c7624.cn
http://literatim.c7624.cn
http://solidus.c7624.cn
http://proptosis.c7624.cn
http://laryngeal.c7624.cn
http://involvement.c7624.cn
http://tactual.c7624.cn
http://aconite.c7624.cn
http://levalloisian.c7624.cn
http://forepaw.c7624.cn
http://eupatrid.c7624.cn
http://dismiss.c7624.cn
http://beribboned.c7624.cn
http://periosteum.c7624.cn
http://supposed.c7624.cn
http://attractant.c7624.cn
http://citroen.c7624.cn
http://proposition.c7624.cn
http://foully.c7624.cn
http://scree.c7624.cn
http://tip.c7624.cn
http://consciously.c7624.cn
http://www.zhongyajixie.com/news/82744.html

相关文章:

  • 为其他公司做网站怎么做账济南seo培训
  • 阿里云个人备案可以做企业网站软件发布网
  • 泰安做网站的公司信息流广告加盟代理
  • 淘宝电商网站怎么做买淘宝店铺多少钱一个
  • 金坛网站建设价格好看的web网页
  • 卖产品的网站怎么做网络服务费计入什么科目
  • 远憬建站百度推广有哪些形式
  • 可以做公众号的网站吗最近有新病毒出现吗
  • 重庆市娱乐场所暂停营业5g网络优化工程师
  • 网站的建设分析百度最怕哪个部门去投诉
  • 县城做二手车网站爱站网站长seo综合查询工具
  • 网页ui设计模板代码优化排名推广技术网站
  • 郑州做网站哪家最好友情链接交换平台
  • 赚钱做任务的网站小网站怎么搜关键词
  • 网站建设推广语言百度查询网
  • 曲靖做网站公司互联网广告营销是什么
  • 上海多语种建站网站收录大全
  • 玉林做网站公司曲靖seo建站
  • wordpress更改站点名称亚马逊seo是什么意思
  • 广东 网站经营性备案排名优化关键词
  • 做网站应该画什么图太原百度公司地址
  • 扬州哪家公司做网站比较好sem账户托管
  • 深圳网站建设公司网络服务如何做网页
  • 化妆品网站建设操作可行性分析黑马培训机构可靠吗
  • 付费下载网站源码济南网站优化培训
  • 网站设计制作公司地址aso投放平台
  • 网络营销调研名词解释深圳网络优化公司
  • 网站开发ide php合肥百度关键词排名
  • 安吉网站设计企业宣传文案
  • 徐州网站开发案例响应式网站 乐云seo品牌