Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✨ Added solution to 876
  • Loading branch information
Sathish Babu committed May 19, 2020
commit f94d02e163462c13a94073308d7a1953f218bc4f
14 changes: 12 additions & 2 deletions src/0876.Middle-of-the-Linked-List/Solution.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
package Solution

func Solution(x bool) bool {
return x
type ListNode struct {
Val int
Next *ListNode
}

func Solution(head *ListNode) *ListNode {
tort, hare := head, head
for hare != nil && hare.Next != nil {
tort = tort.Next
hare = hare.Next.Next
}
return tort
}
12 changes: 7 additions & 5 deletions src/0876.Middle-of-the-Linked-List/Solution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
expect bool
inputs *ListNode
expect *ListNode
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase", &ListNode{1, nil}, &ListNode{1, nil}},
{"TestCase", &ListNode{1, &ListNode{2, &ListNode{3, nil}}},
&ListNode{2, &ListNode{3, nil}}},
{"TestCase", &ListNode{1, &ListNode{2, &ListNode{3, &ListNode{4, nil}}}},
&ListNode{3, &ListNode{4, nil}}},
}

// 开始测试
Expand Down