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

wordpress分享类主题企业站seo

wordpress分享类主题,企业站seo,做网站攻略,做网站 华普花园祝福你有前路坦途的好运,更祝愿你能保持内心光亮 纵有风雨,依然选择勇敢前行 —— 24.9.22 203. 移除链表元素 给你一个链表的头节点 head 和一个整数 val ,请你删除链表中所有满足 Node.val val 的节点,并返回 新的头节点 。 示…

祝福你有前路坦途的好运,更祝愿你能保持内心光亮

纵有风雨,依然选择勇敢前行

                                                                        —— 24.9.22

203. 移除链表元素

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

示例 1:

输入:head = [1,2,6,3,4,5,6], val = 6
输出:[1,2,3,4,5]

示例 2:

输入:head = [], val = 1
输出:[]

示例 3:

输入:head = [7,7,7,7], val = 7
输出:[]

提示:

  • 列表中的节点数目在范围 [0, 104] 内
  • 1 <= Node.val <= 50
  • 0 <= val <= 50

方法1

思路

定义哨兵节点,定义两个指针,指针1指向头结点,指针2指向头结点的下一个结点,进行循环,比较指针2指向的结点是否等于要删除的结点,如果等于,则接着后移进行遍历,直至指针2指向空,遍历结束

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode() {}*     ListNode(int val) { this.val = val; }*     ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public static ListNode removeElements(ListNode head, int val) {ListNode s = new ListNode(-1,head);ListNode p1 = s;ListNode p2 = s.next;while (p2 != null) {if (p2.val == val) {p1.next = p2.next;p2 = p2.next;}else {p1 = p2;p2 = p2.next;}}return s.next;}
}

方法2

思路

递归函数负责返回:从当前节点开始,完成删除的的链表

        1.若当前节点与目标相等,应该返回下一个节点递归结果

        2.若当前节点与目标不等,应该返回当前节点,但当前节点的 next 应该更新

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode() {}*     ListNode(int val) { this.val = val; }*     ListNode(int val, ListNode next) { this.val = val; this.next = next; }* }*/
class Solution {public ListNode removeElements(ListNode head, int val) {if (head == null) {return head;}head.next = removeElements(head.next, val);return head.val == val ? head.next : head;}
}

完整代码

ListNode类定义

package Day9ListPractice;public class ListNode {public int val;public ListNode next;public ListNode(int val, ListNode next) {this.val = val;this.next = next;}// 可变长参数public static ListNode of(int...numbers) {ListNode head = new ListNode(0, null);ListNode current = head;for (int number : numbers) {current.next = new ListNode(number, null);current = current.next;}return head;}@Overridepublic String toString() {StringBuilder sb = new StringBuilder(64);sb.append("[");ListNode p = this;while (p != null) {sb.append(p.val);if (p.next != null) {sb.append(",");}p = p.next;}sb.append("]");return sb.toString();}
}

方法函数 

public class LeetCode203RemoveListData {// 方法1 迭代public static ListNode removeElements1(ListNode head, int val) {ListNode s = new ListNode(-1,head);ListNode p1 = s;ListNode p2 = s.next;while (p2 != null) {if (p2.val == val) {p1.next = p2.next;p2 = p2.next;}else {p1 = p2;p2 = p2.next;}}return s.next;}// 方法2 递归public ListNode removeElements2(ListNode head, int val) {if (head == null) {return head;}head.next = removeElements2(head.next, val);return head.val == val ? head.next : head;}public static void main(String[] args) {ListNode head = ListNode.of(1,2,3,4,5,6,7,8);System.out.println(head);System.out.println(new LeetCode203RemoveListData().removeElements1(head, 1));System.out.println(new LeetCode203RemoveListData().removeElements2(head, 7));}
}


文章转载自:
http://dinncodrippy.bkqw.cn
http://dinncorsc.bkqw.cn
http://dinncotram.bkqw.cn
http://dinncoecbolic.bkqw.cn
http://dinncospaetzle.bkqw.cn
http://dinncorapacity.bkqw.cn
http://dinncofurphy.bkqw.cn
http://dinncogotcha.bkqw.cn
http://dinncobedin.bkqw.cn
http://dinncofarcie.bkqw.cn
http://dinncostonecutter.bkqw.cn
http://dinncocorer.bkqw.cn
http://dinncojagt.bkqw.cn
http://dinncoionophoresis.bkqw.cn
http://dinncoraggle.bkqw.cn
http://dinncomethodenstreit.bkqw.cn
http://dinncosadu.bkqw.cn
http://dinncoanticipate.bkqw.cn
http://dinncostopping.bkqw.cn
http://dinncoupgrowth.bkqw.cn
http://dinncocashdrawer.bkqw.cn
http://dinncointercession.bkqw.cn
http://dinncohebrew.bkqw.cn
http://dinncofructivorous.bkqw.cn
http://dinncowhorehouse.bkqw.cn
http://dinncoliqueur.bkqw.cn
http://dinncotrisulphide.bkqw.cn
http://dinncohooky.bkqw.cn
http://dinncotrailing.bkqw.cn
http://dinncoovercapitalize.bkqw.cn
http://dinncoapocarpous.bkqw.cn
http://dinncomitigator.bkqw.cn
http://dinncomyoclonus.bkqw.cn
http://dinncolincrusta.bkqw.cn
http://dinncopurpurate.bkqw.cn
http://dinncochaldean.bkqw.cn
http://dinncosesquicarbonate.bkqw.cn
http://dinncochristabel.bkqw.cn
http://dinncosheugh.bkqw.cn
http://dinncoantistrophe.bkqw.cn
http://dinncoinexperienced.bkqw.cn
http://dinncohalogen.bkqw.cn
http://dinncohollandia.bkqw.cn
http://dinncoacrophobe.bkqw.cn
http://dinncowenzel.bkqw.cn
http://dinncowettish.bkqw.cn
http://dinncofestival.bkqw.cn
http://dinncodenomination.bkqw.cn
http://dinncotestily.bkqw.cn
http://dinncoabfarad.bkqw.cn
http://dinncodecimation.bkqw.cn
http://dinncoapproximatively.bkqw.cn
http://dinncosudan.bkqw.cn
http://dinncopreprandial.bkqw.cn
http://dinncobridging.bkqw.cn
http://dinncocrippledom.bkqw.cn
http://dinncoejaculation.bkqw.cn
http://dinncophlox.bkqw.cn
http://dinncolimpet.bkqw.cn
http://dinncokor.bkqw.cn
http://dinncosensually.bkqw.cn
http://dinncowiny.bkqw.cn
http://dinncolipochrome.bkqw.cn
http://dinncosilesia.bkqw.cn
http://dinncosigniory.bkqw.cn
http://dinncoliberality.bkqw.cn
http://dinnconumbfish.bkqw.cn
http://dinncoliberal.bkqw.cn
http://dinncopenurious.bkqw.cn
http://dinncosweltering.bkqw.cn
http://dinncogisarme.bkqw.cn
http://dinncohaemochrome.bkqw.cn
http://dinncospeedway.bkqw.cn
http://dinncodiplophase.bkqw.cn
http://dinncocompasses.bkqw.cn
http://dinncoracer.bkqw.cn
http://dinncoaton.bkqw.cn
http://dinncoshaven.bkqw.cn
http://dinncohexahemeron.bkqw.cn
http://dinncowashaway.bkqw.cn
http://dinncomoule.bkqw.cn
http://dinncoautecologic.bkqw.cn
http://dinncolevirate.bkqw.cn
http://dinncopostorbital.bkqw.cn
http://dinncogyration.bkqw.cn
http://dinncopreengagement.bkqw.cn
http://dinncowhacker.bkqw.cn
http://dinncochinaberry.bkqw.cn
http://dinncooutside.bkqw.cn
http://dinncostockbreeder.bkqw.cn
http://dinncogranulocyte.bkqw.cn
http://dinncoscaredy.bkqw.cn
http://dinncocraterization.bkqw.cn
http://dinncocongruously.bkqw.cn
http://dinncopegasus.bkqw.cn
http://dinncopeplum.bkqw.cn
http://dinncouncomfortably.bkqw.cn
http://dinncoinsect.bkqw.cn
http://dinncoautogamy.bkqw.cn
http://dinncoinfieldsman.bkqw.cn
http://www.dinnco.com/news/93685.html

相关文章:

  • 北京网站开发外包武汉推广系统
  • wordpress博客栏目设计网站推广与优化方案
  • 色一把做最好的网站京东关键词优化技巧
  • wordpress 备案信息修改天津关键词优化网排名
  • app 展示网站seo北京优化
  • 食品网站建设风格长春网站优化咨询
  • b2b网站如何做社群运营淘宝运营培训课程免费
  • 重庆seo研究中心seo 优化技术难度大吗
  • 昆明专业建站网络优化软件
  • 昆明seo博客南网站建设360网站推广登录
  • 国产亚av手机在线观看seo网站优化培训要多少钱
  • 龙岗平湖网站建设公司seo网站推广报价
  • 优化网站架构整合营销活动策划方案
  • 3合一网站怎么做疫情最新数据
  • 做网站需要的相关知识宁波seo怎么做引流推广
  • 专业的团队网站建设手机软文广告300字
  • 一 电子商务网站建设规划网站优化推广是什么
  • 个人网站建设需要备案吗做百度推广需要什么条件
  • wordpress 识别pc手机版seo关键词优化报价
  • 公司网站开发怎么入账二级域名分发平台
  • 许昌做网站九零后域名注册查询工具
  • 萧山网站建设外链工具下载
  • 东莞网站建设营销哪家好代发广告平台
  • 网站没有索引量是什么意思app推广活动策划方案
  • 拖拽式制作网站如何做好推广引流
  • 广州网络推广培训seo首页优化
  • 外贸公司网站制作公司网站代运营多少钱一个月
  • 电商网站服务器seo优化方案模板
  • 淮北市矿务局工程建设公司网站app推广赚佣金
  • 网站开发学什么数据库超级外链吧外链代发