AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
# 1. 题目描述 给定一个有环链表,返回第一个入环节点。 # 2. 题解 快慢指针 ~~~ /** * 快慢指针 * @param list 待判断有环链表 * @return 环入口或者null */ public Node findStartNode(Node list){ if(list == null) return null; Node fast = list, slow = list; boolean flag = false; while(fast != null && fast.next != null){ slow = slow.next; fast = fast.next.next; if(slow == fast) { flag = true; break; } } if(!flag) return null; fast = list; while(fast != slow){ fast = fast.next; slow = slow.next; } return fast; } ~~~