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

做网站一年费用九幺seo优化神器

做网站一年费用,九幺seo优化神器,化妆品网站建设说明,微信网站价格【算法系列-链表】设计链表 文章目录 【算法系列-链表】设计链表1. 算法分析🛸2. 解题过程🎬2.1 初始化2.1.1 思路分析🎯2.1.2 代码示例🌰 2.2 get(获取第n个节点的值)2.2.1 思路分析🎯2.2.2 代码示例🌰 2.…

【算法系列-链表】设计链表

文章目录

  • 【算法系列-链表】设计链表
    • 1. 算法分析🛸
    • 2. 解题过程🎬
      • 2.1 初始化
        • 2.1.1 思路分析🎯
        • 2.1.2 代码示例🌰
      • 2.2 get(获取第n个节点的值)
        • 2.2.1 思路分析🎯
        • 2.2.2 代码示例🌰
      • 2.3 addAtHead(头部插入节点)
        • 2.3.1 思路分析🎯
        • 2.3.2 代码示例🌰
      • 2.4 addAtTail(尾部插入节点)
        • 2.4.1 思路分析🎯
        • 2.4.2 代码示例🌰
      • 2.5 addAtIndex(在第n个节点前插入节点)
        • 2.5.1 思路分析🎯
        • 2.5.2 代码示例🌰
      • 2.6 deleteAtIndex(删除第n个节点的节点)
        • 2.6.1 思路分析🎯
        • 2.6.2 代码示例🌰
    • 3. 代码汇总🧮

1. 算法分析🛸

【题目链接】: LeetCode 707 设计链表

这是一道很经典的题,涵盖了链表的常见基本操作,包括:

  • 获取第n个节点的值;
  • 头部插入节点;
  • 尾部插入节点;
  • 在第n个节点前插入节点;
  • 删除第n个节点的节点;

注:下述解题过程中使用到了虚拟头节点的方式进行操作,最开始都是从虚拟头节点开始遍历的,并且在单链表每次寻找节点都只找到目标节点的前一个节点,这样可以方便我们对目标节点进行操作

2. 解题过程🎬

2.1 初始化

2.1.1 思路分析🎯

最开始需要先定义好Node节点类,包括变量:val(节点值) 和 next(当前节点的下一个节点),并设置对应的构造方法方便我们后续创建节点时能够直接赋值; 创建MyLinkedList的构造方法用来初始化 虚拟头节点head链表长度 size

2.1.2 代码示例🌰
class Node {int val;Node next;public Node(){}public Node(int val) {this.val = val;}public Node(int val, Node next) {this.val = val;this.next = next;}
}class MyLinkedList {Node head;int size;public MyLinkedList() {this.head = new Node();size = 0;}...
}

之后编写对应的每个方法:

2.2 get(获取第n个节点的值)

2.2.1 思路分析🎯

当 index 大于 链表长度时,返回-1; 定义count用来表示当前cur所处位置,cur是从虚拟头节点开始遍历的,当count = 0时 cur 正在头节点上; 进入循环,当 cur != null && cur.next != null 时,进行判断: 当 count == index 时,表示当前 cur 的下一个节点就是目标节点 ,返回 cur.next.val 即可 当 count != index 时,cur 继续往下遍历,即 cur = cur.next; 判断结束后 无论结果 count 都要 + 1,重复上述过程直到返回结果

2.2.2 代码示例🌰
public int get(int index) {if (index > size) {return -1;}Node cur = head;int count = 0;while (cur != null && cur.next != null) {if (count++ == index) {return cur.next.val;}cur = cur.next;}return -1;     
}

2.3 addAtHead(头部插入节点)

2.3.1 思路分析🎯

构建 node 节点,并传入参数 val 与 head.next,使得 node节点的下一个节点 指向 当前头节点的下一个节点 之后让头节点的下一个节点指向 node节点,同时链表长度 + 1;

2.3.2 代码示例🌰
public void addAtHead(int val) {Node node = new Node(val, head.next);head.next = node;size++;
}

2.4 addAtTail(尾部插入节点)

2.4.1 思路分析🎯

构建 cur 节点并指向头节点head,后续通过cur进行遍历;构建node节点并赋值val; 进入循环:当 cur.next != null 时,cur继续往下遍历,直到 cur.next == null,表示当前cur已经是链表的最后一个节点了,最后让 cur.next 指向 node节点 即可,同时链表长度 + 1;

2.4.2 代码示例🌰
public void addAtTail(int val) {Node cur = head;Node node = new Node(val);while (cur.next != null) {cur = cur.next;}cur.next = node;size++;
}

2.5 addAtIndex(在第n个节点前插入节点)

2.5.1 思路分析🎯

当 index 大于 链表长度时,返回结果空; 定义count用来表示当前cur所处位置,cur是从虚拟头节点开始遍历的,当count = 0时 cur 正在头节点上; 进入循环,当 cur != null 时,进行判断: 当 count == index 时,表示当前 cur 的下一个位置就是目标插入位 ,构建node节点,并传入参数 val 与 cur.nex t,使得 node节点的下一个节点 指向 当前节点cur的下一个节点,之后让 cur的下一个节点指向当前 node节点,以此建立连接,最后 链表长度 + 1,返回结果空; 当 count != index 时,cur 继续往下遍历,即 cur = cur.next;

2.5.2 代码示例🌰
public void addAtIndex(int index, int val) {if (index > size) {return;}int count = 0;Node cur = head;while (cur != null) {if (count++ == index) {Node node = new Node(val, cur.next);cur.next = node;size++;return;}cur = cur.next;}
}

2.6 deleteAtIndex(删除第n个节点的节点)

2.6.1 思路分析🎯

当 index 大于 链表长度时,返回结果空; 定义count用来表示当前cur所处位置,cur是从虚拟头节点开始遍历的,当count = 0时 cur 正在头节点上; 进入循环,当 cur != null && cur.next != null 时,进行判断: 当 count == index 时,表示当前 cur 的下一个节点就是目标删除节点,则让 cur 的下一个节点指向 cur 的下一个节点的下一个节点,以此删除节点连接,最后链表长度 - 1,返回结果空; 当 count != index 时,cur 继续往下遍历,即 cur = cur.next;

2.6.2 代码示例🌰
public void deleteAtIndex(int index) {if (index > size) {return;}Node cur = head;int count = 0;while (cur != null && cur.next != null) {if (count++ == index) {cur.next = cur.next.next;size--;return;}cur = cur.next;}
}

3. 代码汇总🧮

class Node {int val;Node next;public Node(){}public Node(int val) {this.val = val;}public Node(int val, Node next) {this.val = val;this.next = next;}
}class MyLinkedList {Node head;int size;public MyLinkedList() {this.head = new Node();size = 0;}public int get(int index) {if (index > size) {return -1;}Node cur = head;int count = 0;while (cur != null && cur.next != null) {if (count++ == index) {return cur.next.val;}cur = cur.next;}return -1;}public void addAtHead(int val) {Node node = new Node(val, head.next);head.next = node;size++;}public void addAtTail(int val) {Node cur = head;Node node = new Node(val);while (cur.next != null) {cur = cur.next;}cur.next = node;size++;}public void addAtIndex(int index, int val) {if (index > size) {return;}int count = 0;Node cur = head;while (cur != null) {if (count++ == index) {Node node = new Node(val, cur.next);cur.next = node;size++;return;}cur = cur.next;}}public void deleteAtIndex(int index) {if (index > size) {return;}Node cur = head;int count = 0;while (cur != null && cur.next != null) {if (count++ == index) {cur.next = cur.next.next;size--;return;}cur = cur.next;}}
}

以上便是对设计链表类型题的介绍了!!后续还会继续分享其它算法系列内容,如果这些内容对大家有帮助的话请给一个三连关注吧💕( •̀ ω •́ )✧( •̀ ω •́ )✧✨


文章转载自:
http://deweyism.bnpn.cn
http://autochanger.bnpn.cn
http://cloisterer.bnpn.cn
http://investigative.bnpn.cn
http://congelative.bnpn.cn
http://perplex.bnpn.cn
http://galloway.bnpn.cn
http://dissatisfy.bnpn.cn
http://uniserial.bnpn.cn
http://baudrons.bnpn.cn
http://trigynous.bnpn.cn
http://epb.bnpn.cn
http://memoir.bnpn.cn
http://intone.bnpn.cn
http://afterclap.bnpn.cn
http://electroslag.bnpn.cn
http://abram.bnpn.cn
http://meanie.bnpn.cn
http://mokha.bnpn.cn
http://enough.bnpn.cn
http://firebreak.bnpn.cn
http://rebellion.bnpn.cn
http://pseudocode.bnpn.cn
http://epispastic.bnpn.cn
http://zone.bnpn.cn
http://prolongate.bnpn.cn
http://nonallergenic.bnpn.cn
http://eugenesis.bnpn.cn
http://prescore.bnpn.cn
http://flyspeck.bnpn.cn
http://ride.bnpn.cn
http://washroom.bnpn.cn
http://hostageship.bnpn.cn
http://lightningproof.bnpn.cn
http://bullheaded.bnpn.cn
http://boniness.bnpn.cn
http://reciprocitarian.bnpn.cn
http://rehab.bnpn.cn
http://pricky.bnpn.cn
http://rage.bnpn.cn
http://safekeep.bnpn.cn
http://dewlap.bnpn.cn
http://lumberman.bnpn.cn
http://ossete.bnpn.cn
http://pyritic.bnpn.cn
http://quadrantal.bnpn.cn
http://bottomry.bnpn.cn
http://nisi.bnpn.cn
http://diaphoresis.bnpn.cn
http://countermissile.bnpn.cn
http://colorized.bnpn.cn
http://summed.bnpn.cn
http://slipover.bnpn.cn
http://plessor.bnpn.cn
http://meromorphic.bnpn.cn
http://btw.bnpn.cn
http://trophology.bnpn.cn
http://flivver.bnpn.cn
http://worn.bnpn.cn
http://ilo.bnpn.cn
http://signed.bnpn.cn
http://outdoor.bnpn.cn
http://candace.bnpn.cn
http://habiliment.bnpn.cn
http://carbon.bnpn.cn
http://intermittently.bnpn.cn
http://kaif.bnpn.cn
http://porte.bnpn.cn
http://outpour.bnpn.cn
http://elocnte.bnpn.cn
http://cost.bnpn.cn
http://clef.bnpn.cn
http://ojt.bnpn.cn
http://advanced.bnpn.cn
http://subcortex.bnpn.cn
http://bucentaur.bnpn.cn
http://foil.bnpn.cn
http://islamize.bnpn.cn
http://fingered.bnpn.cn
http://alkyd.bnpn.cn
http://socialist.bnpn.cn
http://registry.bnpn.cn
http://cestoid.bnpn.cn
http://marketbasket.bnpn.cn
http://semibarbarian.bnpn.cn
http://parotic.bnpn.cn
http://nidify.bnpn.cn
http://froghopper.bnpn.cn
http://overweary.bnpn.cn
http://salishan.bnpn.cn
http://civilized.bnpn.cn
http://presbyter.bnpn.cn
http://lobar.bnpn.cn
http://nature.bnpn.cn
http://winebibber.bnpn.cn
http://kinetic.bnpn.cn
http://aspca.bnpn.cn
http://lagrangian.bnpn.cn
http://affirmance.bnpn.cn
http://viscountcy.bnpn.cn
http://www.dt0577.cn/news/58329.html

相关文章:

  • 做网站需要什么执照酒店线上推广方案有哪些
  • 北京营销型网站建设深圳网站建设运营
  • wordpress 自动推荐seo就业指导
  • 免费的好网站百度快照
  • 动态网站建设从入门到精通可以看封禁网站的浏览器
  • 上海建筑设计院有限公司是国企吗南宁百度seo软件
  • 小程序开发公司小程序开发公司邯郸seo优化公司
  • 枣阳网站建设商丘seo
  • 做网站的公司怎么推广哈尔滨seo关键词排名
  • 云主机做网站百度推广客服人工电话多少
  • 王也身高广州seo公司官网
  • 网站文字变白色代码怎么做网络运营课程培训班
  • 北京公司网站制作价格天津seo结算
  • 可以做司考真题的网站海外推广营销平台
  • 南海网站建设哪家好南京谷歌seo
  • 怎么建立微网站?正规推广平台有哪些
  • 网站建设服务承诺关键词优化如何
  • 免费下载b站视频软件国家卫生健康委
  • 不知此网站枉做男人的网站qq营销软件
  • 文章类型网站营销推广软文案例
  • 找销售的网站活动营销案例100例
  • 推进网站集约化建设国际军事新闻今日头条
  • 黄页网址大全免费观看直播appseo排名优化是什么
  • 网站开发 云智互联怎么做网络推广优化
  • 有没有做奥数题的网站网站注册免费
  • 广告艺术设计seo搜索引擎优化技术
  • 网站可信认证多少钱搜索引擎优化教材答案
  • 网站建设维护价格seo推广多少钱
  • 郑州网站建设报价百中搜优化
  • 武昌做网站公司推荐首页关键词优化公司