Skip to content

Commit 0c5f250

Browse files
aQuaaQua
aQua
authored and
aQua
committed
109 adding
1 parent fd5aaed commit 0c5f250

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# [109. Convert Sorted List to Binary Search Tree](https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/)
2+
3+
## 题目
4+
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.
5+
6+
## 解题思路
7+
8+
见程序注释
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package Problem0109
2+
3+
import (
4+
"github.com/aQuaYi/LeetCode-in-Golang/kit"
5+
)
6+
7+
type ListNode = kit.ListNode
8+
type TreeNode = kit.TreeNode
9+
10+
func sortedListToBST(head *ListNode) *TreeNode {
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package Problem0109
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func Test_Problem0109(t *testing.T) {
11+
ast := assert.New(t)
12+
13+
// tcs is testcase slice
14+
tcs := []struct {
15+
head []int
16+
ans []int
17+
}{
18+
19+
{
20+
[]int{},
21+
nil,
22+
},
23+
24+
{
25+
[]int{1, 2, 3, 4, 5, 6, 7, 8},
26+
[]int{1, 2, 3, 4, 5, 6, 7, 8},
27+
},
28+
29+
// 可以多个 testcase
30+
}
31+
32+
for _, tc := range tcs {
33+
fmt.Printf("~~%v~~\n", tc)
34+
35+
ast.Equal(tc.ans, sortedListToBST(tc.head), "输入:%v", tc)
36+
}
37+
}

0 commit comments

Comments
 (0)