NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
``` // 初始化快慢指针,指针是指向对象结点的引用 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)