Skip to content

Commit 765bb77

Browse files
committed
Update solution 0141
1 parent 23beddc commit 765bb77

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

leetcode/0141.Linked-List-Cycle/141. Linked List Cycle_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ func Test_Problem141(t *testing.T) {
3030

3131
{
3232
para141{[]int{3, 2, 0, -4}},
33-
ans141{true},
33+
ans141{false},
3434
},
3535

3636
{
3737
para141{[]int{1, 2}},
38-
ans141{true},
38+
ans141{false},
3939
},
4040

4141
{

website/content/ChapterFour/0100~0199/0141.Linked-List-Cycle.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,25 @@ Can you solve it without using extra space?
2323

2424
package leetcode
2525

26+
import (
27+
"github.com/halfrost/LeetCode-Go/structures"
28+
)
29+
30+
// ListNode define
31+
type ListNode = structures.ListNode
32+
2633
/**
2734
* Definition for singly-linked list.
28-
* struct ListNode {
29-
* int val;
30-
* ListNode *next;
31-
* ListNode(int x) : val(x), next(NULL) {}
32-
* };
35+
* type ListNode struct {
36+
* Val int
37+
* Next *ListNode
38+
* }
3339
*/
3440

3541
func hasCycle(head *ListNode) bool {
3642
fast := head
3743
slow := head
38-
for slow != nil && fast != nil && fast.Next != nil {
44+
for fast != nil && fast.Next != nil {
3945
fast = fast.Next.Next
4046
slow = slow.Next
4147
if fast == slow {
@@ -45,6 +51,7 @@ func hasCycle(head *ListNode) bool {
4551
return false
4652
}
4753

54+
4855
```
4956

5057

0 commit comments

Comments
 (0)