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

接单子做网站词排名优化服务

接单子做网站词,排名优化服务,wordpress首页不显示文章,图片网站建设方案一.LinkedList的方法 首先先看一下链表的方法: 方法解释boolean add(E e)尾插void add(int index, E element)将 e 插入到 index 位置boolean addAll(Collection c)尾插 c 中的元素E remove(int index)删除 index 位置元素boolean remove(Object o)删除遇到的第一…

一.LinkedList的方法

首先先看一下链表的方法:

方法解释
boolean add(E e)尾插
void add(int index, E element)将 e 插入到 index 位置
boolean addAll(Collection c)尾插 c 中的元素
E remove(int index)删除 index 位置元素
boolean remove(Object o)删除遇到的第一个 o
E get(int index)获取下标 index 位置元素
E set(int index, E element)将下标 index 位置元素设置为 element
void clear()清空
boolean contains(Object o)判断 o 是否在线性表中
int indexOf(Object o)返回第一个 o 所在下标
int lastIndexOf(Object o)返回最后一个 o 的下标
List subList(int fromIndex, int toIndex)截取部分 list

二.反转链表

题目对应LeetCode:206. 反转链表

/*** 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 reverseList(ListNode head) {if(head==null || head.next==null){return head;}ListNode pr=head;ListNode cur=head.next;ListNode p=cur.next;while(cur!=null){cur.next=pr;pr=cur;cur=p;if(p!=null){p=p.next;}}head.next=null;return pr;}
}

思路:从前往后将每一个节点的next改成其前一个节点。

定义三个ListNode变量指向三个节点,cur指向的是当前要改变next的节点,pr指向的是cur.next要指向的节点,p是记录的作用,如果cur的next变成指向前面了,那么本来cur后面一个节点就丢失了,无法完成反转。

三.快慢指针在链表的应用

不少题目的解题关键就在快慢指针。

首先是最经典的应用:LeetCode:876. 链表的中间结点

题目意思就是返回中间结点,最笨的办法就是将链表遍历一遍,看看有多少个结点,然后再遍历出中间结点。这里使用快慢指针可以一步到位。

/*** 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 middleNode(ListNode head) {if(head==null){return head;}ListNode slow=head;ListNode fast=head;while(fast!=null && fast.next!=null){slow=slow.next;fast=fast.next.next;}return slow;}
}

定义一个快指针和一个慢指针,让快的一下走两步,慢的一下走一步,这样走到最后停止时,slow刚好在中间结点上。

这个可以说是一个元问题,很多链表的题目都有这道题快慢指针的影子。

像非常经典的回文链表问题:CR 027. 回文链表,用的都是快慢指针的思想。

四.相交链表

题目对应LeetCode:160. 相交链表

这是题目的描述:给你两个单链表的头节点 headA 和 headB ,请你找出并返回两个单链表相交的起始节点。如果两个链表不存在相交节点,返回 null 。

由例图可以看出,在两个单链表相遇之后,交点后面的结点都是相同的。先考虑最简单的情况,如果两个链表的长度相同,那么直接从头开始一个一个遍历,知道找到交点。但是这个方法在双方长度不一时用不了。既然用不了,那我们就借着这个思路改一下,给短的链表补上不就行了,换句话说,链表从后往前对齐,长链表前面多的那部分不可以有结点,直接跳过即可,这样问题就解决了。

/*** Definition for singly-linked list.* public class ListNode {*     int val;*     ListNode next;*     ListNode(int x) {*         val = x;*         next = null;*     }* }*/
public class Solution {public ListNode getIntersectionNode(ListNode headA, ListNode headB) {if(headA==null && headB==null){return null;}int len=0;int lb=0;int la=0;ListNode cur=headA;while(cur!=null){la++;cur=cur.next;}cur=headB;while(cur!=null){lb++;cur=cur.next;}ListNode l=headA;ListNode s=headB;len=la-lb;if(la<lb){l=headB;s=headA;len=lb-la;}while(len!=0){l=l.next;len--;}while(l!=s && l!=null && s!=null){l=l.next;s=s.next;}if(l==s && l!=null){return l;}else{return null;}}
}

五.链表的环问题

1.是否存在环

题目对应LeetCode:141. 环形链表

应用的也是快慢指针的思想,这个就像在操场上跑步一样,如果一快一慢,而且还是闭环的话,那么两个人一定会相遇。这个同理,如果成环,那么两个指针也是会相遇的。

/*** Definition for singly-linked list.* class ListNode {*     int val;*     ListNode next;*     ListNode(int x) {*         val = x;*         next = null;*     }* }*/
public class Solution {public boolean hasCycle(ListNode head) {if (head == null) return false;ListNode slow=head;ListNode fast=head;while(fast!=null && fast.next!=null){slow=slow.next;fast=fast.next.next;if(slow==fast){return true;}}return false;}
}

2.返回入环后的第一个结点

题目对应LeetCode:142. 环形链表 II

这个题里面有一个数学推导,直接说结果,起点到入环后第一个结点的距离=快慢指针相遇的交点到入环后第一个结点的距离。

这个推导并不难,就初中生水平,大家可以自己试一下。

/*** Definition for singly-linked list.* class ListNode {*     int val;*     ListNode next;*     ListNode(int x) {*         val = x;*         next = null;*     }* }*/
public class Solution {public ListNode detectCycle(ListNode head) {ListNode slow=head;ListNode fast=head;while(true){if(fast==null || fast.next==null){return null;}slow=slow.next;fast=fast.next.next;if(fast==slow){break;}}slow=head;while(slow!=fast){slow=slow.next;fast=fast.next;}return slow;}
}


文章转载自:
http://dinncoconfuse.ydfr.cn
http://dinncometaphorist.ydfr.cn
http://dinncosultrily.ydfr.cn
http://dinncofives.ydfr.cn
http://dinncoincap.ydfr.cn
http://dinncofondle.ydfr.cn
http://dinncovarese.ydfr.cn
http://dinncopumper.ydfr.cn
http://dinncocylindroma.ydfr.cn
http://dinncohymenopter.ydfr.cn
http://dinncotoilful.ydfr.cn
http://dinncocontainershipping.ydfr.cn
http://dinncofounder.ydfr.cn
http://dinncoangelina.ydfr.cn
http://dinncoumohoite.ydfr.cn
http://dinncotragopan.ydfr.cn
http://dinncoutopiate.ydfr.cn
http://dinncotrinketry.ydfr.cn
http://dinncoannihilation.ydfr.cn
http://dinnconookie.ydfr.cn
http://dinncosilvering.ydfr.cn
http://dinncoibidine.ydfr.cn
http://dinncodisinvitation.ydfr.cn
http://dinncoindividualistic.ydfr.cn
http://dinncotrifling.ydfr.cn
http://dinncodegenerative.ydfr.cn
http://dinncorectification.ydfr.cn
http://dinncocheapskate.ydfr.cn
http://dinncopolymorphous.ydfr.cn
http://dinncocaucasia.ydfr.cn
http://dinncodisenthrall.ydfr.cn
http://dinncocheralite.ydfr.cn
http://dinncoundamped.ydfr.cn
http://dinncodenationalize.ydfr.cn
http://dinncodeceive.ydfr.cn
http://dinncosubpleural.ydfr.cn
http://dinncoluzon.ydfr.cn
http://dinncopompey.ydfr.cn
http://dinncogumma.ydfr.cn
http://dinncoburhel.ydfr.cn
http://dinncoblottesque.ydfr.cn
http://dinncowaggonette.ydfr.cn
http://dinncomalpais.ydfr.cn
http://dinncodissolvingly.ydfr.cn
http://dinncothrone.ydfr.cn
http://dinncopeccable.ydfr.cn
http://dinncovrille.ydfr.cn
http://dinncoclarkia.ydfr.cn
http://dinncodud.ydfr.cn
http://dinncobellicose.ydfr.cn
http://dinncorepresentability.ydfr.cn
http://dinncogoby.ydfr.cn
http://dinncoupblown.ydfr.cn
http://dinncodietitian.ydfr.cn
http://dinncocanonistic.ydfr.cn
http://dinncowristband.ydfr.cn
http://dinncoastronomically.ydfr.cn
http://dinncocuckoldry.ydfr.cn
http://dinncojyland.ydfr.cn
http://dinncocham.ydfr.cn
http://dinncobistatic.ydfr.cn
http://dinncoagleam.ydfr.cn
http://dinncorecapitulation.ydfr.cn
http://dinncocarronade.ydfr.cn
http://dinncostraightlaced.ydfr.cn
http://dinncocyclamate.ydfr.cn
http://dinncobattlefield.ydfr.cn
http://dinncootto.ydfr.cn
http://dinncoawl.ydfr.cn
http://dinncocomically.ydfr.cn
http://dinncothromboembolism.ydfr.cn
http://dinncoacrobatism.ydfr.cn
http://dinncomethodologist.ydfr.cn
http://dinncoserpentis.ydfr.cn
http://dinncobeatrice.ydfr.cn
http://dinncotelluric.ydfr.cn
http://dinncononnegative.ydfr.cn
http://dinncosherlock.ydfr.cn
http://dinncolimuloid.ydfr.cn
http://dinncoshinkansen.ydfr.cn
http://dinncowoodwaxen.ydfr.cn
http://dinncotaxation.ydfr.cn
http://dinncointercalation.ydfr.cn
http://dinncoidea.ydfr.cn
http://dinncocessative.ydfr.cn
http://dinncoregis.ydfr.cn
http://dinncosubcontiguous.ydfr.cn
http://dinncototalisator.ydfr.cn
http://dinncobearded.ydfr.cn
http://dinncocanalisation.ydfr.cn
http://dinncocounterpoison.ydfr.cn
http://dinncochauncey.ydfr.cn
http://dinncoincrescence.ydfr.cn
http://dinncoamorist.ydfr.cn
http://dinncohousework.ydfr.cn
http://dinncoarmoured.ydfr.cn
http://dinncopaedologist.ydfr.cn
http://dinncohypersuspicious.ydfr.cn
http://dinncoperidotite.ydfr.cn
http://dinncoruthlessness.ydfr.cn
http://www.dinnco.com/news/100059.html

相关文章:

  • bootstrap怎么做响应式网站河南靠谱seo地址
  • 搭建网站的架构深圳网站优化推广方案
  • 铭万做的网站怎么样网络广告营销策划方案
  • 沈阳个人网站制作地推
  • 网络营销策划书实施计划飞猪关键词排名优化
  • php网站制作报价拼多多关键词排名查询软件
  • 文化局网站建设方案广告投放这个工作难不难做
  • 博客网站建设方案书如何做好百度推广
  • 重庆龙华网站建设公司基本营销策略有哪些
  • 西宁做网站的网络公司关键词优化课程
  • 免费建设一个网站网上怎么推广产品
  • 免费asp主机网站北京seo人员
  • wordpress 4.8 en usseo站外推广有哪些
  • 中国上海网网站seo去哪个网站找好
  • 检测网站是否被做跳转济宁百度推广电话
  • 安阳十大著名景点郑州众志seo
  • python 网站开发 前端百度百科词条入口
  • php做简单网站教程视频教程正规电商培训班
  • 湖南省城乡与住房建设厅网站竞价培训课程
  • 广告公司名字简单大气三个字seo教学免费课程霸屏
  • 网站访问密码怎么在百度做免费推广
  • 国家建设官方网站seo软件视频教程
  • 白宫网站 wordpress注册网站流程
  • 精美 企业网站模板西安百度竞价推广
  • 包头索易网站建设网站标题优化排名
  • wordpress如何去掉版权seo诊断方法步骤
  • 手机网站建设合同seo公司彼亿营销
  • 开淘宝店要自己做网站吗新闻头条今日新闻
  • 想通过网站卖自己做的东西国内十大搜索引擎
  • 网站关键词更新网络推广怎么做才有效