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

台州路桥做网站的公司有哪些商业空间设计的特点

台州路桥做网站的公司有哪些,商业空间设计的特点,那个网站可以找人做兼职,重庆会计之家是谁做的网站提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言一、力扣876. 链表的中间结点二、力扣142. 环形链表 II三、力扣160. 相交链表四、力扣141. 环形链表 前言 一、力扣876. 链表的中间结点 /*** Definition for …

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 一、力扣876. 链表的中间结点
  • 二、力扣142. 环形链表 II
  • 三、力扣160. 相交链表
  • 四、力扣141. 环形链表


前言


一、力扣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) {ListNode res = new ListNode(-1,head);ListNode p = head;int len = 0;while(p != null){p = p.next;len ++;}int i = len / 2 + 1;p = head;for(int j = 1; j < i; j ++){p = p.next;}return p;}
}

快慢指针遍历一次

/*** 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) {ListNode dump = new ListNode(-1,head);ListNode p1 = dump, p2 = dump;for(; p2 != null;){p1 = p1.next;p2 = p2.next;if(p2 == null){return p1;}p2 = p2.next;}return p1;}
}

二、力扣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 p1 = head, p2 = head;while(p1 != null && p2 != null && p2.next != null){p1 = p1.next;p2 = p2.next.next;if(p1 == p2){p1 = head;while(p1 != p2){p1 = p1.next;p2 = p2.next;}return p1;}}return null;}
}

三、力扣160. 相交链表

/*** 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) {ListNode p1 = headA, p2 = headB;int len1 = 0, len2 = 0;while(p1 != null){len1 ++;p1 = p1.next;}while(p2 != null){len2 ++;p2 = p2.next;}ListNode fast, slow;int edge = 0;if(len1 > len2){edge = len1 - len2;fast = headA;slow = headB;}else{edge = len2 - len1;fast = headB;slow = headA;}while(edge > 0){edge --;fast = fast.next;}while(fast != null && slow != null){if(fast == slow){return fast;}fast = fast.next;slow = slow.next;}return 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) {ListNode p1 = headA, p2 = headB;while(p1 != p2){if(p1 == null) p1 = headB;else p1 = p1.next;if(p2 == null) p2 = headA;else p2 = p2.next;}return p1;}
}

四、力扣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) {ListNode p1 = head, p2 = head;while(p1 != null && p2 != null  && p2.next != null){p1 = p1.next;p2 = p2.next.next;if(p1 == p2){return true;}}return false;}
}
http://www.yayakq.cn/news/504510/

相关文章:

  • 做公司网站好处小学培训机构
  • 如何建导航网站中国网站设计公司
  • 怎么做微信网站推广网络推广员工作好做吗
  • php做网站的重点2345浏览器免费版
  • seo网站优化网站编辑招聘wordpress 主题制作教程
  • html5的篮球网站开发企业资质证书查询官方网站
  • 做下一个盗版小说网站网站建设国际标准
  • 网站建设 制作教程 pdf凡科登录入口官网
  • 新手建站广告联盟赚钱wordpress转播
  • 国外网站问题泉州彩票网站建设
  • 网站建设费能算作无形资产吗一个网站建设的成本
  • 取消网站验证码seo优化排名百度教程
  • 手机上怎么制作网站山西企业网站模板建站平台
  • 用台式机做网站服务器报考建设八大员官方网站
  • 装修网站建设方案书柳州网站开发公司
  • 设计图的网站乐山网站公众号建设
  • 网站做微信小程序桂林两江四湖是哪两江哪四湖
  • 邓卅做网站在什么地方广州云购网站建设
  • 东莞网站建设 硅橡胶海外网站seo
  • 北京网站开发需要多少钱wordpress 企业知识库
  • 在线推广企业网站的方法有哪些优化网站排名哪家好
  • 如何把网站主关键词做到百度首页前端 模板 网站
  • 企业网站一般用什么程序做网站建设咨询有客诚信
  • 做医疗设备的网站企业网站建设源码
  • 公司网站备案怎么弄网站建设时送的ppt方案
  • 简述软件开发流程虚拟主机对网站seo有哪些影响
  • 网站seo李守洪排名大师长辛店镇网站建设
  • 郑州优化网站公司wordpress繁体
  • 这样可以做网站排版设计模板
  • 做品牌推广用什么网站做推广哪个网站最热门