🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
``` // 初始化快慢指针,指针是指向对象结点的引用 ListNode slow = head; ListNode fast = head; /** * Change this condition to fit specific problem. * Attention: remember to avoid null-pointer error **/ while (slow != null && fast != null && fast.next != null) { slow = slow.next; // move slow pointer one step each time fast = fast.next.next; // move fast pointer two steps each time if (slow == fast) { // change this condition to fit specific problem //是环形链表 return true; } } //不是环形链表 return false; ``` ***** ![](https://img.kancloud.cn/59/15/5915530d34aa37f706dc37cbf7b184b1_827x263.png) ***** ![](https://img.kancloud.cn/ee/63/ee63e2111e3b721a9894b607383d8f15_828x407.png)