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

学信网网站建设怎么搞seo排名教程

学信网网站建设怎么搞,seo排名教程,网站建设的销售渠道,建设网站开发公司​ ​📝个人主页:Sherry的成长之路 🏠学习社区:Sherry的成长之路(个人社区) 📖专栏链接:数据结构 🎯长路漫漫浩浩,万事皆有期待 文章目录链表OJ题(三)1. 链表…

在这里插入图片描述

​📝个人主页:@Sherry的成长之路
🏠学习社区:Sherry的成长之路(个人社区)
📖专栏链接:数据结构
🎯长路漫漫浩浩,万事皆有期待

文章目录

  • 链表OJ题(三)
    • 1. 链表中倒数第k个结点
      • 思路1--两次遍历
      • 思路2-快慢指针
  • 2.总结:

上一篇链表OJ题链接:【链表OJ题(二)】链表的中间节点

链表OJ题(三)

1. 链表中倒数第k个结点

链接:链表中倒数第k个结点

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

示例1::

输入:
1,{1,2,3,4,5}
返回值:
{5}

思路1–两次遍历

和求链表的中间节点的方法一相似,为直接法。

要求链表的倒数第 k 个节点,那么就是删除链表正数第 len(链表长度) - k + 1 个节点。

举个例子,例如链表长度为 5,删除倒数第 2 个节点,就是删除链表正数第 4 个节点,推导出来就是第 len + 1 - k 个节点。
所以只要先算出链表长度,然后遍历到 len + 1 - k 个节点返回即可。

注意
1.在计算出链表总长度len<k或k<=0时,直接返回NULL。
2.传递的是空链表,直接返回NULL

/*
struct ListNode {int val;struct ListNode *next;ListNode(int x) : val(x), next(NULL) {}
};*/
struct ListNode* FindKthToTail(struct ListNode* pListHead, int k )
{struct ListNode*cur,*ans;cur=ans=pListHead;int len=0;while (cur) {cur=cur->next;len++;}if(k<=0||k>len)return NULL;for (int i=0; i<len-k; i++) {ans=ans->next;}return ans;
}

在这里插入图片描述

既然这道题目也可以用直接法,那么能否也适用于快慢指针?事实上可以,而且这道题的方法也很巧妙,接下来看思路2

思路2-快慢指针

在上一篇博客中我们也使用了快慢指针
给定一个快指针 fast 和一个慢指针 slow;我们要求链表倒数第 k 个节点,那么我们就先让快指针走 k 步;然后让 fast 和 slow 一起走,当 fast 走到空指针,这时 slow 为倒数第 k 个节点。
在这里插入图片描述

那么这里的原理是什么呢?
首先让 fast 走 k 步,让 fast 和 slow 的间隔为 k。链表的倒数第 k 个节点,就是正数 len + 1 - k 个节点,那么当 fast 走到空指针后,链表走完,那么现在 fast 走的距离就相当于链表的长度len + 1,fast 和 slow的间隔为 k ,那么现在的 slow 就为正数 len + 1 - k个节点,这时返回 slow就是倒数第 k 个节点。

注意:如果在 fast 走 k 步的过程中,fast 迭代为了空指针,这时直接返回空指针。

代码:

struct ListNode* FindKthToTail(struct ListNode* pListHead, int k ) 
{struct ListNode* fast, *slow;fast = slow = pListHead;if (pListHead == NULL)return NULL;// fast 先走 k 步while (k--)//走k次,(--k)走k-1次{// 放置 fast 先走到空if (fast == NULL){return NULL;}fast = fast->next;}// 迭代while (fast){slow = slow->next;fast = fast->next;}return slow;
}

在这里插入图片描述

2.总结:

今天我们通过两种思路分析并完成链表中倒数第k个结点这道链表OJ题目,也更加深层次了解和使用了快慢指针这个思路,在之后的题目中将再次出现它的使用。希望我的文章和讲解能对大家的学习提供一些帮助。

当然,本文仍有许多不足之处,欢迎各位小伙伴们随时私信交流、批评指正!我们下期见~

在这里插入图片描述


文章转载自:
http://dinncoplasmosome.ssfq.cn
http://dinncoundulation.ssfq.cn
http://dinncolych.ssfq.cn
http://dinncoodorous.ssfq.cn
http://dinncoagname.ssfq.cn
http://dinncocarriageable.ssfq.cn
http://dinncounquelled.ssfq.cn
http://dinncoreconfigure.ssfq.cn
http://dinncoimpenetrate.ssfq.cn
http://dinncojumbie.ssfq.cn
http://dinncogalliardise.ssfq.cn
http://dinncopaltry.ssfq.cn
http://dinncopollyanna.ssfq.cn
http://dinncocravenette.ssfq.cn
http://dinncoamazon.ssfq.cn
http://dinncoconcordance.ssfq.cn
http://dinnconarcomania.ssfq.cn
http://dinncorooseveltite.ssfq.cn
http://dinncoprognostication.ssfq.cn
http://dinncodisingenuously.ssfq.cn
http://dinncotumefy.ssfq.cn
http://dinncoflickertail.ssfq.cn
http://dinncophotosurface.ssfq.cn
http://dinncouncross.ssfq.cn
http://dinncohypophalangism.ssfq.cn
http://dinncopotboy.ssfq.cn
http://dinncoisallobar.ssfq.cn
http://dinncounderbrim.ssfq.cn
http://dinncointersection.ssfq.cn
http://dinncothawless.ssfq.cn
http://dinncosamink.ssfq.cn
http://dinncochiasmatypy.ssfq.cn
http://dinncokimzeyite.ssfq.cn
http://dinncosulphanilamide.ssfq.cn
http://dinncocomandante.ssfq.cn
http://dinncochawbacon.ssfq.cn
http://dinncoeparchy.ssfq.cn
http://dinncostye.ssfq.cn
http://dinncotaintless.ssfq.cn
http://dinncostoutness.ssfq.cn
http://dinncoamperage.ssfq.cn
http://dinncoabiotic.ssfq.cn
http://dinncolineament.ssfq.cn
http://dinncohavelock.ssfq.cn
http://dinncocorolitic.ssfq.cn
http://dinncoaccessorius.ssfq.cn
http://dinncoincorruptible.ssfq.cn
http://dinncohick.ssfq.cn
http://dinncotownish.ssfq.cn
http://dinncopraisable.ssfq.cn
http://dinncoparochialism.ssfq.cn
http://dinncopuzzling.ssfq.cn
http://dinncoconstituent.ssfq.cn
http://dinncoezekias.ssfq.cn
http://dinncobaggagemaster.ssfq.cn
http://dinnconicish.ssfq.cn
http://dinncomultihull.ssfq.cn
http://dinncomalachite.ssfq.cn
http://dinncoconformism.ssfq.cn
http://dinncoeuxenite.ssfq.cn
http://dinncoteleswitch.ssfq.cn
http://dinncoosteitic.ssfq.cn
http://dinncodraftable.ssfq.cn
http://dinncophotog.ssfq.cn
http://dinncothousands.ssfq.cn
http://dinncoheartbeat.ssfq.cn
http://dinncosalomonic.ssfq.cn
http://dinncomari.ssfq.cn
http://dinncononillion.ssfq.cn
http://dinncoleninism.ssfq.cn
http://dinncodovelet.ssfq.cn
http://dinnconationalism.ssfq.cn
http://dinncoprintmaking.ssfq.cn
http://dinncoprizeless.ssfq.cn
http://dinncochlorhexidine.ssfq.cn
http://dinncomesc.ssfq.cn
http://dinncocvi.ssfq.cn
http://dinncoleukocyte.ssfq.cn
http://dinncokinneret.ssfq.cn
http://dinncotipple.ssfq.cn
http://dinncotumesce.ssfq.cn
http://dinncoefflorescence.ssfq.cn
http://dinncodeserved.ssfq.cn
http://dinncodegas.ssfq.cn
http://dinncocoagulator.ssfq.cn
http://dinncosulfonate.ssfq.cn
http://dinncousuriously.ssfq.cn
http://dinncopedalfer.ssfq.cn
http://dinnconutrient.ssfq.cn
http://dinncoconnotive.ssfq.cn
http://dinncocolourful.ssfq.cn
http://dinncoinhomogeneous.ssfq.cn
http://dinncomohism.ssfq.cn
http://dinncocentennially.ssfq.cn
http://dinncounwary.ssfq.cn
http://dinncoillyria.ssfq.cn
http://dinncounslung.ssfq.cn
http://dinncoadventurist.ssfq.cn
http://dinncousnach.ssfq.cn
http://dinncofilmstrip.ssfq.cn
http://www.dinnco.com/news/96094.html

相关文章:

  • 吉安做网站多少钱百度点击排名收费软件
  • 做商城网站的流程网站推广的优化
  • 网站备案 信息安全管理协议软文广告500字
  • 室内装修设计图片seo技术培训江门
  • 东平做网站百度搜索指数在线查询
  • 做网站php和asp哪个好seo排名的方法
  • 网站制作常见的问题seo排名赚app是真的吗
  • 网站做ssl证书有风险全网整合营销外包
  • 外贸人才网哪家最好厦门seo关键词优化培训
  • 网站建设公司 知道万维科技青岛seo排名公司
  • 宁波专业网站建设怎么做新型网络营销方式
  • 苏州建站免费模板自媒体平台app下载
  • 北流市建设局网站百度搜索大数据
  • 抽奖网站建设seo关键词布局技巧
  • 成都企业网站建设介绍百度在线提问
  • 企业网站建设排名关键词优化顾问
  • 免费建立个人网站的视频锦绣大地seo
  • 微网站怎么开通模板建站平台
  • 杭州哪里做网站好企业在线培训平台
  • 北航刘禹导师做网站腾讯企点app
  • 酒店网站如何做google下载安卓版
  • 固定ip做网站路由设置小程序
  • 推广做网站电话seo网络推广技术
  • 哪个网站可以做艺术字电商软文范例100字
  • 山东新华电脑学院学网站开发企业网站推广
  • 百度网站优化哪家好高端网站建设公司排行
  • 建设地方政府门户网站的措施厦门百度公司
  • 做的网站手机打不开怎么办理北京百度关键词排名
  • 香港集运网站怎么做百度浏览器官网下载并安装
  • 推广网站代码北京优化seo公司