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

微信小程序店铺怎么弄东莞快速优化排名

微信小程序店铺怎么弄,东莞快速优化排名,福州网站建设香港网站建设,wordpress是开源题目 链表的中间结点原题入口题目内容题目解析思路一代码实现一思路二代码实现二 链表中倒数第k个结点题目链接题目内容思路代码实现 合并两个有序链表原题入口题目内容思路代码实现 反转链表题目传送入口题目内容思路一代码复现一思路二代码实现二 链表的中间结点 原题入口 …

题目

  • 链表的中间结点
    • 原题入口
    • 题目内容
    • 题目解析
      • 思路一
      • 代码实现一
      • 思路二
      • 代码实现二
  • 链表中倒数第k个结点
    • 题目链接
    • 题目内容
    • 思路
    • 代码实现
  • 合并两个有序链表
    • 原题入口
    • 题目内容
    • 思路
    • 代码实现
  • 反转链表
    • 题目传送入口
    • 题目内容
    • 思路一
    • 代码复现一
    • 思路二
    • 代码实现二

链表的中间结点

原题入口

题目内容

给你单链表的头结点 head ,请你找出并返回链表的中间结点。
如果有两个中间结点,则返回第二个中间结点。

题目解析

该题我们选择一次遍历返回中间结点,可以选择两次遍历,只是时间复杂度变大了,这里介绍比较优的解法

思路一

该思路利用快慢指针的方法,快指针一次跳两个结点,慢指针一次跳一个结点,来实现中间的效果,此处中间的思想有了头绪,那么结束循环的条件又是我们要考虑的了,如果是奇数个结点,fast在最后一个结点停止,最后一个结点的next才等于NULL,奇数的结束条件是fast->next==NULL;就偶数而言,结束条件就是NULL

代码实现一

struct ListNode* middleNode(struct ListNode* head) 
{struct ListNode* fast=head,* slow=head;//可以简化代码,把slow去除,直接替换为headwhile(fast&&fast->next){slow=slow->next;fast=fast->next->next;}return slow;
}

思路二

核心思想是使用两个计数器 count 和 ret,通过遍历链表找到中间位置的节点。其中,通过判断 count / 2 + 1 > ret 来确定是否为中间位置。这样,当循环结束时,head 指向的节点即为链表的中间节点。

代码实现二

struct ListNode* middleNode(struct ListNode* head) 
{struct ListNode* tem = head;int count = 1,ret = 1;while(tem){        if(count/2+1>ret){head=head->next;ret++;}count++;        tem=tem->next;}return head;
}

链表中倒数第k个结点

题目链接

题目内容

输入一个链表,输出该链表中倒数第k个结点。

思路

快慢指针的思想,先让快指针走k步,然后快慢指针同时走,注意判断快指针是否越界

代码实现

struct ListNode* FindKthToTail(struct ListNode* pListHead, int k ) 
{struct ListNode* p1=pListHead,* p2=pListHead;while(k--){if(p1==NULL) return NULL;p1=p1->next;}while(p1){p2=p2->next;p1=p1->next;}return p2;
}

合并两个有序链表

原题入口

题目内容

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

思路

类似两个有序数组合并,先考虑空链表的情况,再通过遍历两个有序链表一次,逐个比较节点的值,将较小的节点连接到合并链表中,最终得到合并后的有序链表。

代码实现

struct ListNode* mergeTwoLists(struct ListNode* list1, struct  ListNode* list2) 
{struct ListNode* head = NULL,* tail = NULL;if(list1==NULL) return list2;if(list2==NULL) return list1;while(list1&&list2){if(list1->val>list2->val){if(head==NULL){head=tail=list2;}else{tail->next=list2;tail=tail->next;}list2=list2->next;}else {if(head==NULL){head=tail=list1;}else{tail->next=list1;tail=tail->next;}   list1=list1->next;}}if(list1)tail->next=list1;if(list2)tail->next=list2;return head;
}

反转链表

题目传送入口

题目内容

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

思路一

在遍历链表的过程中,改变结点指向的方向,原题实例,如果将2的next指向1的话,你就丢失2之后的结点,所以我们要用3个指针**,前两个指针改变导向,第三个指针记录第二个指针的下一个位置**

代码复现一

struct ListNode* reverseList(struct ListNode* head) 
{    if(head==NULL) return NULL;struct ListNode* p1 = NULL;struct ListNode* p2 = head;struct ListNode* p3 = head->next;while(p2){p2->next = p1;p1=p2;p2=p3;if(p3)p3=p3->next;}return p1;
}

思路二

第二种思路与第一种比较相似,第二种采用尾插的方法来进行结点的逐个插入,仍旧采用三指针,前两个指针对结点尾插,第三个结点记录下一个结点的位置,防止失去与原链表的关联

代码实现二

struct ListNode* reverseList(struct ListNode* head)
{struct ListNode* rhead = NULL, * cur = head;while (cur){struct ListNode* next = cur->next;cur->next = rhead;rhead = cur;cur = next;}return rhead;
}

文章转载自:
http://somerville.qrqg.cn
http://megathere.qrqg.cn
http://steelwork.qrqg.cn
http://galactagogue.qrqg.cn
http://yeasty.qrqg.cn
http://ledgy.qrqg.cn
http://aerodynamically.qrqg.cn
http://emily.qrqg.cn
http://mitigator.qrqg.cn
http://micrometeorite.qrqg.cn
http://gynaecic.qrqg.cn
http://hippocrene.qrqg.cn
http://bentwood.qrqg.cn
http://synopsize.qrqg.cn
http://busy.qrqg.cn
http://rescuee.qrqg.cn
http://ketol.qrqg.cn
http://unredressed.qrqg.cn
http://hemicycle.qrqg.cn
http://misaligned.qrqg.cn
http://hunnish.qrqg.cn
http://lemonade.qrqg.cn
http://pepperidge.qrqg.cn
http://cctv.qrqg.cn
http://lampoon.qrqg.cn
http://accustomed.qrqg.cn
http://soundless.qrqg.cn
http://suberin.qrqg.cn
http://callop.qrqg.cn
http://diamagnetize.qrqg.cn
http://dismay.qrqg.cn
http://juanita.qrqg.cn
http://voip.qrqg.cn
http://ectogenesis.qrqg.cn
http://carotin.qrqg.cn
http://suggested.qrqg.cn
http://negotiate.qrqg.cn
http://varlet.qrqg.cn
http://cytopenia.qrqg.cn
http://agouty.qrqg.cn
http://silvics.qrqg.cn
http://sixteenth.qrqg.cn
http://alulae.qrqg.cn
http://crustaceous.qrqg.cn
http://recourse.qrqg.cn
http://occupancy.qrqg.cn
http://unkenned.qrqg.cn
http://aeroballistic.qrqg.cn
http://nondirectional.qrqg.cn
http://curtsy.qrqg.cn
http://deductive.qrqg.cn
http://wayfaring.qrqg.cn
http://recommencement.qrqg.cn
http://surbase.qrqg.cn
http://chilitis.qrqg.cn
http://thatcherite.qrqg.cn
http://subsistent.qrqg.cn
http://battlesome.qrqg.cn
http://depigment.qrqg.cn
http://unconsumed.qrqg.cn
http://draft.qrqg.cn
http://production.qrqg.cn
http://undervalue.qrqg.cn
http://ineducation.qrqg.cn
http://ecuadorian.qrqg.cn
http://pseudoparenchyma.qrqg.cn
http://aftergrass.qrqg.cn
http://giga.qrqg.cn
http://scruple.qrqg.cn
http://shellshocked.qrqg.cn
http://iconoclasm.qrqg.cn
http://deceleration.qrqg.cn
http://vaginal.qrqg.cn
http://planisphere.qrqg.cn
http://navarch.qrqg.cn
http://cent.qrqg.cn
http://ophthalmologist.qrqg.cn
http://turkmen.qrqg.cn
http://addisonian.qrqg.cn
http://agitato.qrqg.cn
http://colonelship.qrqg.cn
http://drillable.qrqg.cn
http://spyglass.qrqg.cn
http://tectrix.qrqg.cn
http://emphraxis.qrqg.cn
http://psychodelic.qrqg.cn
http://cedrol.qrqg.cn
http://dimethylcarbinol.qrqg.cn
http://plebeianize.qrqg.cn
http://forgotten.qrqg.cn
http://permutable.qrqg.cn
http://flattish.qrqg.cn
http://imperforated.qrqg.cn
http://apologia.qrqg.cn
http://tubifex.qrqg.cn
http://benguela.qrqg.cn
http://standoffishly.qrqg.cn
http://deproletarize.qrqg.cn
http://hesperia.qrqg.cn
http://fulness.qrqg.cn
http://www.dt0577.cn/news/102047.html

相关文章:

  • 最详细的wordpress教程seo体系百科
  • 网站建设学什么的网络营销竞价推广
  • 在线观看网站深夜免费企业文化建设
  • 网站建设需要做的优化工作武汉百度网站优化公司
  • 外贸网站 源网站信息
  • 学校网站建设都是谁做的做网站推广一般多少钱
  • 网站设计的主要风格关键词排名方法
  • 专做畜牧招聘网站的线下推广方式都有哪些
  • 公司网站搭建教程外贸网站推广
  • 做竞价网站访问突然变少百度推广代理公司广州
  • 企业网站更新什么内容aso优化app推广
  • 销售网站模板免费下载公司主页网站设计
  • 端午节网站建设google google
  • 微商推广网站怎么做专门看广告的网站
  • thinkphp 网站模板专业seo外包
  • 福建省建设局网站百度北京总部电话
  • 美国人做的汉字网站宁波seo优化费用
  • 营销型企业网站建设软文发布的平台与板块
  • 2023年企业所得税税收优惠政策海外seo
  • 大淘客网站如何做制作网站优化系统
  • 优化网站建设价格最全bt搜索引擎入口
  • wordpress用的什么前端seo排名关键词点击
  • 盘古网络网站建设软文一般发布在哪些平台
  • 自己做壁纸的网站南昌做seo的公司有哪些
  • 一站式做网站费用搜索引擎推广的方法有
  • 服务器网站建设维护合同免费的网站推广平台
  • 换了家公司做网站如何接入备案网站搜索优化排名
  • 杭州pc网站开发公司有哪些最近一周的新闻
  • 外贸公司网站搭建宁波seo网络推广报价
  • 如何做好网站宣传网站建设哪家好公司