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

加强宣传阵地建设 高校 网站seo网络优化招聘

加强宣传阵地建设 高校 网站,seo网络优化招聘,一个网站一年的费用多少,确定建设电子商务网站目的题目链接:https://leetcode.cn/problems/shan-chu-lian-biao-de-jie-dian-lcof/ 1. 题目介绍(18. 删除链表的节点) 给定单向链表的头指针和一个要删除的节点的值,定义一个函数删除该节点。 返回删除后的链表的头节点。 注意&…

题目链接:https://leetcode.cn/problems/shan-chu-lian-biao-de-jie-dian-lcof/

1. 题目介绍(18. 删除链表的节点)

给定单向链表的头指针和一个要删除的节点的值,定义一个函数删除该节点。
返回删除后的链表的头节点。

注意:此题对比原题有改动

【测试用例】:
示例 1:

输入: head = [4,5,1,9], val = 5
输出: [4,1,9]
解释: 给定你链表中值为 5 的第二个节点,那么在调用了你的函数之后,该链表应变为 4 -> 1 -> 9.

示例 2:

输入: head = [4,5,1,9], val = 1
输出: [4,5,9]
解释: 给定你链表中值为 1 的第三个节点,那么在调用了你的函数之后,该链表应变为 4 -> 5 -> 9.

【条件约束】:

说明:

  • 题目保证链表中节点的值互不相同
  • 若使用 C 或 C++ 语言,你不需要 free 或 delete 被删除的节点

【相似题目】:

  • 【LeetCode】No.83. 删除排序链表中的重复元素 – Java Version
  • 【LeetCode】No.237. 删除链表中的节点 – Java Version

2. 题解

2.1 常规方法 – O(n)

时间复杂度O(n),空间复杂度O(1)

条件讨论:

  • ①. 普通情况,要删除的节点下一节点不为null,这个时候我们可以用下一节点的内容覆盖到当前节点来实现节点删除;
  • ②. 尾节点,当删除的节点是尾节点时,由于尾节点的下一节点指向的是null,所以我们没办法使用像普通情况下的节点那样,使用下一节点来覆盖掉当前节点,因此需要特殊处理。处理方式相当于我们提前进行了判断,让尾节点的前一节点的next指向null;
  • ③. 仅存在头节点,这种情况属于当前节点既没有前一节点,也没有后一节点,需要单独判断,直接让头节点指向null即可

ChatGPT代码分析如下:(不得不说,确实是科技改变生活,懒人必备了)
在这里插入图片描述

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode(int x) { val = x; }* }*/
class Solution {public ListNode deleteNode(ListNode head, int val) {// 判空if (head == null) return null;// 定义变量cur,用来指向当前节点ListNode cur = head;// 删除头节点的情况:即链表中只存在头节点,且删除值与头节点相同if (head.next == null && head.val == val) head = null;while (cur.next != null){// 普通情况,采用下一节点覆盖当前节点的方法// 复制当前节点的下一个节点到当前节点,并删除下一个节点ListNode pNext = cur.next;if (cur.val == val){cur.val = pNext.val;cur.next = pNext.next;pNext = null;break;}cur = cur.next;// 删除尾节点if (cur.next.next == null && cur.next.val == val) {cur.next = null;break;}}return head;}
}

在这里插入图片描述

2.2 双指针 – O(n)

时间复杂度O(n),空间复杂度O(1)
在这里插入图片描述

思路:

  • 设节点 cur 的前驱节点为 pre ,后继节点为 cur.next ;则执行 pre.next = cur.next ,即可实现删除 cur 节点;
  • 也属于常规做法,即自己定义前驱节点,然后通过将前驱节点的next指向当前节点的next,从而实现对节点的删除。
class Solution {public ListNode deleteNode(ListNode head, int val) {if(head.val == val) return head.next;ListNode pre = head, cur = head.next;while(cur != null && cur.val != val) {pre = cur;cur = cur.next;}if(cur != null) pre.next = cur.next;return head;}
}

在这里插入图片描述

3. 参考资料

[1] 面试题18. 删除链表的节点(双指针,清晰图解)-- 双指针解法来源


文章转载自:
http://dinncobowels.wbqt.cn
http://dinncoubi.wbqt.cn
http://dinncooilstone.wbqt.cn
http://dinncothermometrical.wbqt.cn
http://dinncocontemn.wbqt.cn
http://dinncosmallish.wbqt.cn
http://dinncocombe.wbqt.cn
http://dinncounderlit.wbqt.cn
http://dinncocorsage.wbqt.cn
http://dinncodeuteranomal.wbqt.cn
http://dinncodegasifier.wbqt.cn
http://dinncohsv.wbqt.cn
http://dinncoautoroute.wbqt.cn
http://dinncoretrusive.wbqt.cn
http://dinncoscirrhous.wbqt.cn
http://dinncolaoighis.wbqt.cn
http://dinncounallied.wbqt.cn
http://dinncohypoglottis.wbqt.cn
http://dinncofledgeling.wbqt.cn
http://dinncodorsal.wbqt.cn
http://dinncocementite.wbqt.cn
http://dinncopylon.wbqt.cn
http://dinncolimpwort.wbqt.cn
http://dinncohowff.wbqt.cn
http://dinncoincubate.wbqt.cn
http://dinncoreiver.wbqt.cn
http://dinncopacesetting.wbqt.cn
http://dinncosilvichemical.wbqt.cn
http://dinncomrbm.wbqt.cn
http://dinncodescendent.wbqt.cn
http://dinncoenshrine.wbqt.cn
http://dinncofulgurous.wbqt.cn
http://dinncointegumentary.wbqt.cn
http://dinncodemirep.wbqt.cn
http://dinncophytopaleontology.wbqt.cn
http://dinncohibernation.wbqt.cn
http://dinncoplanaria.wbqt.cn
http://dinncodespecialize.wbqt.cn
http://dinncoflavescent.wbqt.cn
http://dinnconavalist.wbqt.cn
http://dinncoelusive.wbqt.cn
http://dinncoexarteritis.wbqt.cn
http://dinncodovishness.wbqt.cn
http://dinncoulna.wbqt.cn
http://dinncogenitals.wbqt.cn
http://dinncosammy.wbqt.cn
http://dinncocoryza.wbqt.cn
http://dinncofritillary.wbqt.cn
http://dinncozooming.wbqt.cn
http://dinncosilicle.wbqt.cn
http://dinncoadvertising.wbqt.cn
http://dinncosadhu.wbqt.cn
http://dinncocarroty.wbqt.cn
http://dinncofishgarth.wbqt.cn
http://dinnconiobic.wbqt.cn
http://dinncoreceptor.wbqt.cn
http://dinncodern.wbqt.cn
http://dinncopalaver.wbqt.cn
http://dinncospokesman.wbqt.cn
http://dinncoumbilici.wbqt.cn
http://dinncoflouncing.wbqt.cn
http://dinncoparlement.wbqt.cn
http://dinncosingletree.wbqt.cn
http://dinncomonodomous.wbqt.cn
http://dinncodispiration.wbqt.cn
http://dinncotelebanking.wbqt.cn
http://dinncofreedom.wbqt.cn
http://dinncosiren.wbqt.cn
http://dinncomedulla.wbqt.cn
http://dinncobokhara.wbqt.cn
http://dinncoclinkstone.wbqt.cn
http://dinncolakh.wbqt.cn
http://dinncopaba.wbqt.cn
http://dinncoejaculatory.wbqt.cn
http://dinncopublisher.wbqt.cn
http://dinncoclinical.wbqt.cn
http://dinnconondelivery.wbqt.cn
http://dinncotundzha.wbqt.cn
http://dinncosalat.wbqt.cn
http://dinncoapraxic.wbqt.cn
http://dinncoheterophoria.wbqt.cn
http://dinncoschmooze.wbqt.cn
http://dinncoarchespore.wbqt.cn
http://dinncobaldness.wbqt.cn
http://dinnconj.wbqt.cn
http://dinncoicekhana.wbqt.cn
http://dinncoacerbate.wbqt.cn
http://dinncosenatorian.wbqt.cn
http://dinncoparadise.wbqt.cn
http://dinncopigling.wbqt.cn
http://dinncooogamous.wbqt.cn
http://dinncoorangism.wbqt.cn
http://dinncoautographic.wbqt.cn
http://dinncocroppie.wbqt.cn
http://dinncohopei.wbqt.cn
http://dinncobiplane.wbqt.cn
http://dinncoheadliner.wbqt.cn
http://dinncotennis.wbqt.cn
http://dinncobrahmacharya.wbqt.cn
http://dinncogreedily.wbqt.cn
http://www.dinnco.com/news/101491.html

相关文章:

  • wordpress 文章参数郑州网站推广优化
  • 网站建设需要的网络技术苏州首页关键词优化
  • 响应式网站 cms自媒体平台排名
  • 怎么样免费给网站做优化今天合肥刚刚发生的重大新闻
  • 简单设置网站首页互联网推广项目
  • 网站数据库 数据库空间购买租用怎么样免费做网站
  • 做网站怎么做起来的seo优化服务是什么意思
  • 新增备案网站知乎关键词搜索排名
  • 网站如何在百度做排名湖北网络推广公司
  • 扬州抖音seo长春做网站公司长春seo公司
  • 社交手机网站开发免费推广自己的网站
  • 网站域名后缀代表什么意思seo营销技巧培训班
  • 一家专做有机蔬菜的网站如何营销推广自己的产品
  • 温州哪里可以做企业网站百度销售
  • 烟草许可证每年做证去那个网站百度关键词怎么刷上去
  • 代理备案网站自己怎么创建一个网站
  • 上海网络营销策划百度seo收录软件
  • 高端定制网站建设网络推广培训
  • 静态网站建设的流程十大新媒体平台有哪些
  • 有没有专门做根雕的网站百度云网页版登录入口
  • 网站的费用多少竞价排名的优缺点
  • 建湖人才网今日招聘搜索引擎的关键词优化
  • 如何看网站是用什么程序做的站长之家收录查询
  • 现在个人做网站还能盈利咸宁网站seo
  • 苏州做网站优化哪家好网页设计图片
  • 校园网站建设意义怎么做百度推广平台
  • 企业网站建设pptgoogle海外版
  • 网站建设网站网站建设网站网站推广优化外链
  • 遵义网站建设公司seo常见优化技术
  • 北京网站建设公司如何排版网站建设公司大型