mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-10 14:36:06 +00:00
feat(go/tree): support array binary tree (#655)
This commit is contained in:
@@ -13,7 +13,7 @@ func preOrderI(root *TreeNode, res *[]*TreeNode) {
|
||||
if root == nil {
|
||||
return
|
||||
}
|
||||
if int(root.Val) == 7 {
|
||||
if (root.Val).(int) == 7 {
|
||||
// 记录解
|
||||
*res = append(*res, root)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ func preOrderII(root *TreeNode, res *[][]*TreeNode, path *[]*TreeNode) {
|
||||
}
|
||||
// 尝试
|
||||
*path = append(*path, root)
|
||||
if int(root.Val) == 7 {
|
||||
if root.Val.(int) == 7 {
|
||||
// 记录解
|
||||
*res = append(*res, *path)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func preOrderIII(root *TreeNode, res *[][]*TreeNode, path *[]*TreeNode) {
|
||||
}
|
||||
// 尝试
|
||||
*path = append(*path, root)
|
||||
if int(root.Val) == 7 {
|
||||
if root.Val.(int) == 7 {
|
||||
// 记录解
|
||||
*res = append(*res, *path)
|
||||
*path = (*path)[:len(*path)-1]
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
func TestPreorderTraversalICompact(t *testing.T) {
|
||||
/* 初始化二叉树 */
|
||||
root := ArrToTree([]any{1, 7, 3, 4, 5, 6, 7})
|
||||
root := SliceToTree([]any{1, 7, 3, 4, 5, 6, 7})
|
||||
fmt.Println("\n初始化二叉树")
|
||||
PrintTree(root)
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestPreorderTraversalICompact(t *testing.T) {
|
||||
|
||||
func TestPreorderTraversalIICompact(t *testing.T) {
|
||||
/* 初始化二叉树 */
|
||||
root := ArrToTree([]any{1, 7, 3, 4, 5, 6, 7})
|
||||
root := SliceToTree([]any{1, 7, 3, 4, 5, 6, 7})
|
||||
fmt.Println("\n初始化二叉树")
|
||||
PrintTree(root)
|
||||
|
||||
@@ -50,7 +50,7 @@ func TestPreorderTraversalIICompact(t *testing.T) {
|
||||
|
||||
func TestPreorderTraversalIIICompact(t *testing.T) {
|
||||
/* 初始化二叉树 */
|
||||
root := ArrToTree([]any{1, 7, 3, 4, 5, 6, 7})
|
||||
root := SliceToTree([]any{1, 7, 3, 4, 5, 6, 7})
|
||||
fmt.Println("\n初始化二叉树")
|
||||
PrintTree(root)
|
||||
|
||||
@@ -70,7 +70,7 @@ func TestPreorderTraversalIIICompact(t *testing.T) {
|
||||
|
||||
func TestPreorderTraversalIIITemplate(t *testing.T) {
|
||||
/* 初始化二叉树 */
|
||||
root := ArrToTree([]any{1, 7, 3, 4, 5, 6, 7})
|
||||
root := SliceToTree([]any{1, 7, 3, 4, 5, 6, 7})
|
||||
fmt.Println("\n初始化二叉树")
|
||||
PrintTree(root)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user