u
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package top100liked
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// https://leetcode.cn/problems/binary-tree-inorder-traversal/?envType=study-plan-v2&envId=top-100-liked
|
||||
|
||||
type TreeNode struct {
|
||||
Val int
|
||||
Left *TreeNode
|
||||
Right *TreeNode
|
||||
}
|
||||
|
||||
func inorderTraversal(root *TreeNode) []int {
|
||||
if root == nil {
|
||||
return []int{}
|
||||
}
|
||||
res := []int{}
|
||||
if root.Left != nil {
|
||||
res = append(res, inorderTraversal(root.Left)...)
|
||||
}
|
||||
res = append(res, root.Val)
|
||||
if root.Right != nil {
|
||||
res = append(res, inorderTraversal(root.Right)...)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func Test1(t *testing.T) {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user