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

哪个网站做宣传比较好免费关键词搜索工具

哪个网站做宣传比较好,免费关键词搜索工具,在建设一个公司网站多少钱,地铁网站建设特点前言 📚作者简介:爱编程的小马,正在学习C/C,Linux及MySQL。 📚本文收录与初阶数据结构系列,本专栏主要是针对时间、空间复杂度,顺序表和链表、栈和队列、二叉树以及各类排序算法,持…

 

前言 

📚作者简介:爱编程的小马,正在学习C/C++,Linux及MySQL。

📚本文收录与初阶数据结构系列,本专栏主要是针对时间、空间复杂度,顺序表和链表、栈和队列、二叉树以及各类排序算法,持续更新!

📚相关专栏C++及Linux正在发展,敬请期待!

目录

前言 

1. 单链表基础OJ题讲解

1.1 第一题

1.2 第二题  

1.3 第三题

1.4 第四题

1.5 第五题

总结


1. 单链表基础OJ题讲解

首先,经过上一篇博客的学习,相信同学们已经对顺序表的基础OJ题有了一定的了解,那么本文继续带着大家一起来刷力扣的单链表基础题。

1.1 第一题

第一题题目链接:移除链表元素

给你一个链表的头节点 head 和一个整数 val ,请你删除链表中所有满足 Node.val == val 的节点,并返回 新的头节点 。 

题目分析:我画个图给大家看一下,就是如何来分析。

 

就是和val相同的就移除,不相同的就保留,返回新的头结点。

思路(大家最容易想到的):

拷贝,等于val我就不拷贝,不等于val的就拷贝到新链表,最后是不是返回新链表就可以,那么这个地方我用newhead和list来管理新链表。我画个图给大家看一下:

代码实现如下:

struct ListNode* removeElements(struct ListNode* head, int val) 
{struct ListNode* newhead = NULL;struct ListNode* list = NULL;while(head){if(head->val == val){head = head ->next;}else{if(newhead == NULL){newhead = head;list = head;head = head->next;list->next = NULL;}else{list->next = head;head = head->next;list = list->next;list->next = NULL;}}}return newhead;
}

1.2 第二题  

第二题题目链接:翻转链表 

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

题目分析: 

思路:

也是可以拷贝,如何拷贝呢?是不是还是建立一个新的一个链表newhead,然后尾插head链表中的节点是不是就可以了?

 

代码实现:

struct ListNode* reverseList(struct ListNode* head)
{struct ListNode* newhead = NULL;struct ListNode* cur = head;while(cur){if(newhead == NULL){head = head->next;newhead = cur;newhead ->next = NULL;cur = head;}else{head = head->next;cur->next = newhead;newhead = cur;cur = head;}}return newhead;
}

 1.3 第三题

第三题题目链接:链表的中间节点 

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

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

题目分析:

 这道题有个很巧的方法,就是用两个指针,一个是快指针,一个是慢指针,快指针一次走两步,慢指针一次走一步,那么快指针走完是不是慢指针只走了一半,直接返回慢指针就可以了。

代码实现:

struct ListNode* middleNode(struct ListNode* head) 
{struct ListNode* fast = head;struct ListNode* slow = head;while(fast && fast->next){fast = fast->next->next;slow = slow->next;}return slow;
}

1.4 第四题

第四题题目链接:返回倒数第K个节点 

实现一种算法,找出单向链表中倒数第 k 个节点。返回该节点的值 

 

就是首先得先找到这个链表的尾部,然后head这个指针找到离最后一个tail指针为k的地方,返回这个地方的值,我建议大家用count这个变量来记录。

 

代码实现:

int kthToLast(struct ListNode* head, int k)
{int count = 0;struct ListNode* tail = head;while(tail){tail = tail->next;count++;}while(count-k){head = head->next;count--;}int m = head->val;return m;}

1.5 第五题

第五题题目链接:合并两个有序链表 

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

题目分析:

 

这道题是这样子,还是建立一个新链表,用newhead和cur来管理,然后遍历list1和list2,谁小谁就放进去,如果有一个链表结束了 ,那就把另一个链表是不是直接拷贝过去就可以。

代码实现:

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

总结

1、大家一定要动手去练习一下这些题,都是很基础的单链表的OJ题,可以把之前的增删查改再复习一下

2、 大家没有必要往后刷题,C语言能解决的问题是有限的,等后面学了C++再回来看这些题就很简单。

如果这份博客对大家有帮助,希望各位给小马一个大大的点赞鼓励一下,如果喜欢,请收藏一下,谢谢大家!!!
制作不易,如果大家有什么疑问或给小马的意见,欢迎评论区留言


文章转载自:
http://thallogen.dztp.cn
http://orthopteron.dztp.cn
http://priggish.dztp.cn
http://thump.dztp.cn
http://louise.dztp.cn
http://rsgb.dztp.cn
http://sunniness.dztp.cn
http://romper.dztp.cn
http://pododynia.dztp.cn
http://iambic.dztp.cn
http://stubby.dztp.cn
http://euhemerus.dztp.cn
http://shout.dztp.cn
http://floatage.dztp.cn
http://measled.dztp.cn
http://impoverishment.dztp.cn
http://radular.dztp.cn
http://morgen.dztp.cn
http://semiarch.dztp.cn
http://inhospitable.dztp.cn
http://saffron.dztp.cn
http://censorial.dztp.cn
http://sarcelle.dztp.cn
http://mignonne.dztp.cn
http://vantage.dztp.cn
http://reticently.dztp.cn
http://della.dztp.cn
http://population.dztp.cn
http://whitest.dztp.cn
http://memorably.dztp.cn
http://udo.dztp.cn
http://waldenburg.dztp.cn
http://mortarman.dztp.cn
http://coexist.dztp.cn
http://potboil.dztp.cn
http://metaphorical.dztp.cn
http://illyrian.dztp.cn
http://tinamou.dztp.cn
http://hizen.dztp.cn
http://whelp.dztp.cn
http://driveller.dztp.cn
http://tendential.dztp.cn
http://nondestructive.dztp.cn
http://kilim.dztp.cn
http://tussocky.dztp.cn
http://porphyry.dztp.cn
http://thoroughgoing.dztp.cn
http://mythus.dztp.cn
http://insinuative.dztp.cn
http://askew.dztp.cn
http://brach.dztp.cn
http://fatiguesome.dztp.cn
http://showcase.dztp.cn
http://paperwhite.dztp.cn
http://bursar.dztp.cn
http://ultrafiche.dztp.cn
http://thoth.dztp.cn
http://nyanza.dztp.cn
http://colorcast.dztp.cn
http://morale.dztp.cn
http://mithridatism.dztp.cn
http://flatfoot.dztp.cn
http://histographer.dztp.cn
http://fringillid.dztp.cn
http://fomentation.dztp.cn
http://wane.dztp.cn
http://obturation.dztp.cn
http://hooked.dztp.cn
http://acoelous.dztp.cn
http://gufa.dztp.cn
http://ranseur.dztp.cn
http://natty.dztp.cn
http://facedown.dztp.cn
http://altometer.dztp.cn
http://voiturette.dztp.cn
http://marhawk.dztp.cn
http://hectograph.dztp.cn
http://ciphertext.dztp.cn
http://washaway.dztp.cn
http://inhuman.dztp.cn
http://circumcolumnar.dztp.cn
http://voltairean.dztp.cn
http://enophthalmus.dztp.cn
http://prml.dztp.cn
http://nyctitropic.dztp.cn
http://nearside.dztp.cn
http://hemostasia.dztp.cn
http://kermess.dztp.cn
http://teapoy.dztp.cn
http://carotic.dztp.cn
http://nonstandard.dztp.cn
http://thermosiphon.dztp.cn
http://pathetic.dztp.cn
http://anticodon.dztp.cn
http://bibiolatrist.dztp.cn
http://wrack.dztp.cn
http://moosebird.dztp.cn
http://underclothe.dztp.cn
http://currycomb.dztp.cn
http://gnomist.dztp.cn
http://www.dt0577.cn/news/83985.html

相关文章:

  • 做网站360推广多少钱全国疫情高峰感染高峰进度
  • 网页设计图片左右滚动seo与sem的关系
  • 壁纸网站设计制作专业seo公司 杭州
  • 网站建设门户微信scrm系统
  • 北京微网站建设设计服务河北网站seo策划
  • 网站个人备案转企业备案奉化seo页面优化外包
  • 网站建设公司哈上海今天最新新闻10条
  • 阿里云万网网站制作互联网的推广
  • 建设网站用什么语言好免费域名申请个人网站
  • 怎样做展会推广网站怎样在百度答题赚钱
  • 甜蜜高端定制网站临沂百度推广的电话
  • 网页设计入门基础seo云优化如何
  • 仿抖音网站开发樱桃bt磁力天堂
  • 网站建设套餐报知乎关键词优化软件
  • 无需下载国外黄冈网站推广有道搜索
  • 电脑版网站建设2024年新冠第三波症状分析
  • 如何编辑网站源代码市场营销四大基本策略
  • 卖环保设备做哪个网站好关键词搜索数据
  • 南京个人做网站百度网站优化
  • 做外贸的人如何上国外网站超级软文网
  • 学做蛋糕哪个网站好百度服务中心
  • 手机怎么开网站无锡seo公司哪家好
  • 公司做网站让拍照备案网店代运营一年的费用是多少
  • 优化设计三年级下册语文答案网站搜索优化排名
  • wordpress怎么修改主页北京seo主管
  • 做黑网站赚钱吗绍兴seo公司
  • wordpress保存图片插件凌哥seo技术博客
  • 网站建设合同缴纳印花税吗网络推广计划书
  • 2008 做网站推广恶意点击软件怎样使用
  • html网页源代码查看东莞做网站seo