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

企业网站有什么用网站建设 重点

企业网站有什么用,网站建设 重点,东莞有哪家比较好的网站建设公司,上海好的设计公司问题描述 RT. 解决思路 (1) 两链表都是单向链表#xff1a;判断两链表的末尾节点是否相同#xff1b; (2) 两链表中一个有环#xff0c;一个没环#xff1a;不可能相交#xff1b; (3) 两链表都有环#xff1a;slow-fast双指针方法。 程序 public class ListIntersection…问题描述 RT.   解决思路 (1) 两链表都是单向链表判断两链表的末尾节点是否相同 (2) 两链表中一个有环一个没环不可能相交 (3) 两链表都有环slow-fast双指针方法。   程序   public class ListIntersection {// two single listpublic boolean isIntersectionOfTwoSingleList(ListNode l1, ListNode l2) {if (l1 null || l2 null) {return false;}// whether the end of two list is sameListNode endOfList1 getEndOfList(l1);ListNode endOfList2 getEndOfList(l2);return endOfList1 endOfList2;}private ListNode getEndOfList(ListNode head) {if (head null) {return null;}ListNode node head;while (node.next ! null) {node node.next;}return node;}// two list with cyclepublic boolean isIntersectionOfTwoListWithCycle(ListNode l1, ListNode l2) {if (l1 null || l2 null) {return false;}ListNode slow l1, fast l2;while (fast.next ! null || fast ! null || slow ! null) {slow slow.next;fast fast.next.next;if (slow fast) {return true;}}return false;} }Follow up 求出两个链表相交的第一个节点如果存在的话。   (1) 两条单链表 a. 求出两条链表的长度及长度之差diff然后设立两个指针指向两链表的头结点其中指向长链表头结点的指针向前移动diff步 b. 然后同时移动两指针直到所指节点相同地址相同为止否则返回null。   (2) 两条链表有环 首先slow-fast直到相遇为止其中任意一个指针指回其头结点然后slow和fast指针同时移动直到相遇相遇的节点为第一个相交的节点。 注意可能有两个相交的节点   程序 public class ListIntersection2 {// two single listpublic ListNode getFirstIntersectionNodeOfSingleList(ListNode l1,ListNode l2) {ListNode longNode l1, shortNode l2;int len1 getLenOfList(l1);int len2 getLenOfList(l2);if (len1 len2) {longNode l2;shortNode l1;}int diff Math.abs(len1 - len2);// long move diff stepswhile (diff 0) {longNode longNode.next;--diff;}while (longNode ! null shortNode ! null) {if (longNode shortNode) {return longNode;}longNode longNode.next;shortNode shortNode.next;}return null;}private int getLenOfList(ListNode head) {ListNode node head;int len 0;while (node ! null) {len;node node.next;}return len;}// two list with cyclepublic ListNode getFirstIntersectionNodeOfCycleList(ListNode l1, ListNode l2) {if (l1 null || l2 null) {return null;}ListNode slow l1, fast l2;while (fast.next ! null || fast ! null || slow ! null) {if (fast slow) {break;}slow slow.next;fast fast.next.next;}if (fast null || slow null) {return null;}slow l1;while (slow ! fast) {slow slow.next;fast fast.next;}return slow;} }转载于:https://www.cnblogs.com/harrygogo/p/4614277.html
http://www.huolong8.cn/news/371939/

相关文章:

  • 网站建设的要求有哪些方面网络推广seo是什么
  • 百度seo刷排名网址西安软件优化网站建设
  • 洛阳网站建设 培训网站运营与公司
  • 网站的搜索引擎方案安徽建网站公司
  • 做网站需要知道哪些事情做网站 技术
  • wordpress 网站地址如何做网站电话
  • 跨境电商导购网站建设深圳网站建设黄浦网络
  • 网站地图页面深圳市建设监理协会网站
  • 唐山建设网站公司廉江网站制作
  • 怎么做单页竞价网站dede换网站
  • 动漫网站设计方案免费cms
  • 建设银行纪检监察网站免费学网页设计
  • 企业网站建设西安wordpress主题带demo
  • 上海网站建设沪icp备三亚做民宿的都用什么网站
  • 网站建设常用编程语言成都抖音代运营
  • 苏州专业高端网站建设公司哪家好湖南专业做网站公司
  • 高职图书馆网站建设大赛园林景观网站模板
  • 用win2003做网站运营招聘
  • 关注网站建设免费空间资源
  • python个人网站开发北京南站核酸检测地点
  • 制作公司网站设wordpress重置query循环
  • 网站开发环境实验报告做跨国婚恋网站赚钱吗
  • 网站运营专员做六休一中山企业网站推广公司
  • 谢岗镇仿做网站wordpress实惠主机
  • 崇仁网站建设推广费用wordpress图片自动加广告
  • o2o商城网站开发导航网站怎么做的
  • 上海seo网站优化软件app开发公司架构
  • 上海浦东建筑建设网站如何制作ppt视频教程
  • 怎么 从头开始建设一个网站最大郑州网站建设公司
  • 朔州做网站的公司wordpress上传产品