8.18 第一次做,无法 AC
8.19 可以 AC
第一次复习
9.15 可以 A,但不太顺畅
题目描述
力扣:https://leetcode-cn.com/problems/linked-list-cycle/
解题思路:快慢双指针
官方的题解文字表述很不错,可以看,但是代码太冗余了!
代码用我下面的这个就行!
public class Solution {public boolean hasCycle(ListNode head) {ListNode slow = head, fast = head;while(fast != null && fast.next != null) {slow = slow.next;fast = fast.next.next;if(slow == fast) return true;}return false;}}
