Skip to content

Commit 03d69e1

Browse files
committed
897 added
1 parent e0b04c7 commit 03d69e1

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# [897. Increasing Order Search Tree](https://leetcode.com/problems/increasing-order-search-tree/)
2+
3+
## 题目
4+
5+
Given a tree, rearrange the tree in in-order so that the leftmost node in the tree is now the root of the tree, and every node has no left child and only 1 right child.
6+
7+
```text
8+
Example 1:
9+
Input: [5,3,6,2,4,null,8,1,null,null,null,7,9]
10+
11+
5
12+
/ \
13+
3 6
14+
/ \ \
15+
2 4 8
16+
/ / \
17+
1 7 9
18+
19+
Output: [1,null,2,null,3,null,4,null,5,null,6,null,7,null,8,null,9]
20+
21+
1
22+
\
23+
2
24+
\
25+
3
26+
\
27+
4
28+
\
29+
5
30+
\
31+
6
32+
\
33+
7
34+
\
35+
8
36+
\
37+
9
38+
```
39+
40+
Note:
41+
42+
- The number of nodes in the given tree will be between 1 and 100.
43+
- Each node will have a unique integer value from 0 to 1000.
44+
45+
## 解题思路
46+
47+
见程序注释
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package problem0897
2+
3+
import "github.com/aQuaYi/LeetCode-in-Go/kit"
4+
5+
// TreeNode Definition for a binary tree node.
6+
// type TreeNode struct {
7+
// Val int
8+
// Left *TreeNode
9+
// Right *TreeNode
10+
// }
11+
type TreeNode = kit.TreeNode
12+
13+
func increasingBST(root *TreeNode) *TreeNode {
14+
15+
return nil
16+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package problem0897
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/aQuaYi/LeetCode-in-Go/kit"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
var null = kit.NULL
12+
13+
// tcs is testcase slice
14+
var tcs = []struct {
15+
p []int
16+
ans []int
17+
}{
18+
19+
{
20+
[]int{5, 3, 6, 2, 4, null, 8, 1, null, null, null, 7, 9},
21+
[]int{1, null, 2, null, 3, null, 4, null, 5, null, 6, null, 7, null, 8, null, 9},
22+
},
23+
24+
// 可以有多个 testcase
25+
}
26+
27+
func Test_increasingBST(t *testing.T) {
28+
ast := assert.New(t)
29+
30+
for _, tc := range tcs {
31+
fmt.Printf("~~%v~~\n", tc)
32+
root := kit.Ints2TreeNode(tc.p)
33+
ans := kit.Ints2TreeNode(tc.ans)
34+
ast.Equal(ans, increasingBST(root), "输入:%v", tc)
35+
}
36+
}
37+
38+
func Benchmark_myFunc(b *testing.B) {
39+
for i := 0; i < b.N; i++ {
40+
for _, tc := range tcs {
41+
root := kit.Ints2TreeNode(tc.p)
42+
increasingBST(root)
43+
}
44+
}
45+
}

leetcode.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Username": "aQuaYi",
33
"Ranking": 819,
4-
"Updated": "2018-10-07T10:35:14.897835145+08:00",
4+
"Updated": "2018-10-07T10:36:49.583385931+08:00",
55
"Record": {
66
"Easy": {
77
"Solved": 198,

0 commit comments

Comments
 (0)