《leetcode hot100》142. 环形链表 II

Accode:

public class Solution {
    public ListNode detectCycle(ListNode head) {
        ListNode slow = head, fast = head;
        
        while (true) {
            if (fast == null || fast.next == null) return null;
            slow = slow.next;
            fast = fast.next.next;
            if (slow == fast) break;
        }
        
        fast = head;
        while (slow!=fast) {
            slow = slow.next;
            fast = fast.next;
        }
        return slow;
    }
}

over~

相关推荐

  1. leetcode142.环形II

    2024-03-27 02:14:02       70 阅读
  2. 142. 环形 II(Python3)

    2024-03-27 02:14:02       60 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-27 02:14:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-27 02:14:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-27 02:14:02       82 阅读
  4. Python语言-面向对象

    2024-03-27 02:14:02       91 阅读

热门阅读

  1. 实习总结(完)

    2024-03-27 02:14:02       45 阅读
  2. vue3路由懒加载

    2024-03-27 02:14:02       43 阅读
  3. Linux制作yum离线源,解决安装RPM包时循环依赖。

    2024-03-27 02:14:02       41 阅读
  4. C++之函数的重载

    2024-03-27 02:14:02       49 阅读