Skip to content

Commit 23beddc

Browse files
authored
Merge pull request #157 from brenobaptista/cleaned-141
Cleaned 141
2 parents 02999e4 + da7f306 commit 23beddc

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ type ListNode = structures.ListNode
99

1010
/**
1111
* Definition for singly-linked list.
12-
* struct ListNode {
13-
* int val;
14-
* ListNode *next;
15-
* ListNode(int x) : val(x), next(NULL) {}
16-
* };
12+
* type ListNode struct {
13+
* Val int
14+
* Next *ListNode
15+
* }
1716
*/
1817

1918
func hasCycle(head *ListNode) bool {
2019
fast := head
2120
slow := head
22-
for slow != nil && fast != nil && fast.Next != nil {
21+
for fast != nil && fast.Next != nil {
2322
fast = fast.Next.Next
2423
slow = slow.Next
2524
if fast == slow {
Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,54 @@
11
package leetcode
22

3-
import "testing"
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/halfrost/LeetCode-Go/structures"
8+
)
9+
10+
type question141 struct {
11+
para141
12+
ans141
13+
}
14+
15+
// para 是参数
16+
// one 代表第一个参数
17+
type para141 struct {
18+
one []int
19+
}
20+
21+
// ans 是答案
22+
// one 代表第一个答案
23+
type ans141 struct {
24+
one bool
25+
}
426

527
func Test_Problem141(t *testing.T) {
28+
29+
qs := []question141{
30+
31+
{
32+
para141{[]int{3, 2, 0, -4}},
33+
ans141{true},
34+
},
35+
36+
{
37+
para141{[]int{1, 2}},
38+
ans141{true},
39+
},
40+
41+
{
42+
para141{[]int{1}},
43+
ans141{false},
44+
},
45+
}
46+
47+
fmt.Printf("------------------------Leetcode Problem 141------------------------\n")
48+
49+
for _, q := range qs {
50+
_, p := q.ans141, q.para141
51+
fmt.Printf("【input】:%v 【output】:%v\n", p, hasCycle(structures.Ints2List(p.one)))
52+
}
53+
fmt.Printf("\n\n\n")
654
}

0 commit comments

Comments
 (0)