File tree Expand file tree Collapse file tree
solutions/141. Linked List Cycle Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ diff a /solutions /141. Linked List Cycle /AC_Floyd I .java b /solutions /141. Linked List Cycle /AC_Floyd I .java (rejected hunks )
2+ @ @ -0 ,0 +1 ,32 @ @
3+ + /**
4+ + * 1、Floyd判圈法(之前一直叫双指针跑圈法来着)
5+ + *
6+ + *
7+ + */
8+ +/**
9+ + * Definition for singly-linked list.
10+ + * class ListNode {
11+ + * int val;
12+ + * ListNode next;
13+ + * ListNode(int x) {
14+ + * val = x;
15+ + * next = null;
16+ + * }
17+ + * }
18+ + */
19+ +public class Solution {
20+ + public boolean hasCycle (ListNode head ) {
21+ + if (head == null || head .next == null )
22+ + return false ;
23+ +
24+ + ListNode slow = head ;
25+ + ListNode fast = head ;
26+ + do {
27+ + if (fast == null || fast .next == null ) return false ;
28+ +
29+ + slow = slow .next ;
30+ + fast = fast .next .next ;
31+ + }while (slow != fast );
32+ + return true ;
33+ + }
34+ +}
35+ \ No newline at end of file
You can’t perform that action at this time.
0 commit comments