141题:判断链表是不是存在环! // 不能使用额外的存储空间 public boolean hasCycle(ListNode head) { // 如果存在环的 两个指针用不一样的速度 会相遇 ListNode fastNode = head; ListNode slowNode = head; while (fastNode != null && fastNode.next != null) { fastNode = fastNode.next.next; slowNode = sl…
环形链表II 思路 https://www.cnblogs.com/springfor/p/3862125.html https://blog.csdn.net/u010292561/article/details/80444057 假设周长为 S AB + BC + n*S = 2 * ( AB + BC ) => AB = BC + n*S 只要知道了 C 点, 就可以知道 B点了.C点通过快慢指针获得,然后 让一个指针在A点出发,另外一个在C点出发,经过 n 圈,相遇的点就是 AB 点.…
Given a linked list, return the node where the cycle begins. If there is no cycle, return null. To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked list where tail connects to.…