Skip to content

Commit 15a283c

Browse files
committed
refactor Linked List Cycle
1 parent 1025e06 commit 15a283c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

go/linked_list_cycle.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package main
33

44
// `https://github.com/ryo-devz/LeetCode/pull/1#discussion_r1710718113`に書かれているとおり、印をつける方法はデメリットが大きい
55
func hasCycle(head *ListNode) bool {
6-
fast, slow := head, head
6+
slow, fast := head, head
77
for fast != nil && fast.Next != nil {
8-
fast, slow = fast.Next.Next, slow.Next
9-
if fast == slow {
8+
slow, fast = slow.Next, fast.Next.Next
9+
if slow == fast {
1010
return true
1111
}
1212
}

0 commit comments

Comments
 (0)