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

长春地区网站建设/seo网络推广方法

长春地区网站建设,seo网络推广方法,网站最近收录,海港区网站快排seo想想为什么要a走b的路b走a的路 因为这样到达相交点的话是同时的(路程才是一样的) 这样能保证第二圈就相遇了 如果各走各的路很难相遇 两个无交点的链表也有一个null交点 /*** Definition for singly-linked list.* public class ListNode {* int…

 

 

 

想想为什么要a走b的路b走a的路 因为这样到达相交点的话是同时的(路程才是一样的)

这样能保证第二圈就相遇了 如果各走各的路很难相遇

两个无交点的链表也有一个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 A = headA;ListNode B = headB;while(A!=B){A = (A != null?A.next:headB);B = (B != null?B.next:headA);}return A;}
}
//各走各的路
/*** 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 A = headA;ListNode B = headB;int flag = 0;while(A!=B){A = (A != null?A.next:headA);B = (B != null?B.next:headB);if(A == B && B == null){flag ++;if(flag == 2)return A;A = (A != null?A.next:headA);B = (B != null?B.next:headB);}}return A;}
}

 

 

/*** 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) {ListNode cur = head,pre = null;while(cur!= null){ListNode tmp = cur.next;cur.next = pre;//修改next引用指向pre = cur;cur = tmp;}return pre;}
}

 

/*** 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) {return recur(head,null);//递归调用并返回    }private ListNode recur(ListNode cur,ListNode pre){if(cur == null)return pre;//进到这个地方了 然后开始返回ListNode res = recur(cur.next,cur);//递归后面的结点cur.next = pre;return res;}
}

 

 

 

/*** 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 boolean isPalindrome(ListNode head) {//如果链表为空或只有一个结点 就直接返回trueif(head==null||head.next == null)return true;//找到前半部分链表的尾节点ListNode l_End = endOfFirstHalf(head);//反转后半部分链表并找到开头ListNode r_Head = reverseList(l_End.next);//判断是否会问ListNode p1= head;ListNode p2 = r_Head;boolean result = true;while(result==true&&p2 != null){if(p1.val!=p2.val)return false;p1 = p1.next;p2 = p2.next;}// 还原链表并返回结果l_End.next = reverseList(r_Head);return result;}private ListNode reverseList(ListNode head){ListNode pre = null;ListNode cur = head;while(cur != null){ListNode temp = cur.next;cur.next = pre;pre = cur;cur = temp;} return pre;//返回反转后链表的head}private ListNode endOfFirstHalf(ListNode head){ListNode fast = head;ListNode slow = head;while(fast.next!=null&&fast.next.next != null){fast = fast.next.next;slow = slow.next;}return slow;}//慢的走一步 快的走两步
}

 

 

public class Solution {public boolean hasCycle(ListNode head) {if (head == null || head.next == null) {return false;}ListNode slow = head;ListNode fast = head.next;//防止上来就相等while (fast != null && fast.next != null) {//就保证了fast.next.next存在if (slow == fast) {return true;}slow = slow.next; // 慢指针每次移动一步fast = fast.next.next; // 快指针每次移动两步}return false; // 如果快指针到达链表末尾,则没有环}
}
public class Solution {public boolean hasCycle(ListNode head) {if (head == null || head.next == null) {return false;}ListNode slow = head;ListNode fast = head;while (fast != null && fast.next != null) {//就保证了fast.next.next存在slow = slow.next; // 慢指针每次移动一步fast = fast.next.next; // 快指针每次移动两步if (slow == fast) {return true;}}return false; // 如果快指针到达链表末尾,则没有环}
}

 

 

 

慢指针一定还没有走完一圈 

a = (k-1)(b+c) + c   即a == c会在入口处相遇

import java.util.HashSet;
import java.util.Set;public class Solution {public ListNode detectCycle(ListNode head) {Set<ListNode> visited = new HashSet<>();while (head != null) {if (visited.contains(head)) {return head;}visited.add(head);head = head.next;}return null;}
}
public class Solution {public ListNode detectCycle(ListNode head) {if (head == null || head.next == null) {//判断这个就行了 不要多判断return null;}ListNode slow = head;ListNode fast = head;while (fast != null && fast.next != null) {//判断这个就行了slow = slow.next;fast = fast.next.next;if (slow == fast) {ListNode slow2 = head;while (slow != slow2) {//不要写while trueslow = slow.next;slow2 = slow2.next;}return slow;}}return null;}
}

 

/*** 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 mergeTwoLists(ListNode list1, ListNode list2) {ListNode new_head = new ListNode(-101);ListNode cur = new_head;while(list1!=null&&list2!=null){if(list1.val<list2.val){cur.next = list1;list1 = list1.next;}else{cur.next = list2;list2 = list2.next;}cur = cur.next;}// 将剩余的节点连接到合并后的链表末尾cur.next = (list1 != null) ? list1 : list2;//想想为什么这里只用做一个 而不用将剩下的每个节点都做 因为链表存的是指针return new_head.next;}
}

 

 

http://www.whsansanxincailiao.cn/news/31972152.html

相关文章:

  • 商丘简淘网络科技有限公司/搜索引擎优化有哪些要点
  • 移动互联网开发安全案例/sem 优化价格
  • 网站建设源码下载/广东企业网站seo报价
  • 自己做网站 最好的软件下载/营销推广渠道
  • 电子商务网站建设与开发/惠州企业网站建设
  • 做独立网站给你/小程序开发一个多少钱啊
  • 百度推广负责做网站吗/百度站内搜索
  • 可靠的购物网站建设/淘宝推广怎么做
  • 30个适合大学生创业的项目/seo的研究对象
  • 建设银行信用卡网站首页/优秀营销软文范例800字
  • 网站域名防劫持怎么做/大一html网页制作作业
  • 快速建网站/软文推广多少钱一篇
  • 小米路由器 wordpress/前端seo是什么
  • 邯郸做移动网站找谁/百度搜索浏览器
  • 网站给篡改了要怎么做/seo的定义是什么
  • 校园网门户网站建设/广州seo公司如何
  • 临沂网站建设对实体企业/国内最新十大新闻
  • 百度推广怎么做网站的优化/百度关键词怎么优化
  • 黄陂网站建设/网站优化排名金苹果系统
  • wordpress获取标签名/seo推广外包
  • 黄岛网站开发/关键词排名 收录 查询
  • 外贸网站联系方式模板免费/百度指数怎么用
  • 有没有专门做旅游攻略的网站/今日新闻热点大事件
  • 线上设计师提供身份证号/seo查询系统
  • 杭州建设网 执法人员名单/如何进行关键词优化工作
  • 怎么样自己做百度网站/东莞百度搜索优化
  • 做淘宝任务赚钱的网站/青岛神马排名优化
  • 让网站打开更快/2023新闻热点摘抄
  • wordpress做了个站没流量/抖音seo排名
  • 网站网页设计怎么收费/网站外链分析工具