添加新题目
This commit is contained in:
24
二叉树/二叉树的中序遍历/main.go
Normal file
24
二叉树/二叉树的中序遍历/main.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
type TreeNode struct {
|
||||
Val int
|
||||
Left *TreeNode
|
||||
Right *TreeNode
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
func inorderTraversal(root *TreeNode) []int {
|
||||
if root == nil {
|
||||
return []int{}
|
||||
}
|
||||
var res []int
|
||||
leftnode := inorderTraversal(root.Left)
|
||||
rightnode := inorderTraversal(root.Right)
|
||||
res = append(res, leftnode...)
|
||||
res = append(res, root.Val)
|
||||
res = append(res, rightnode...)
|
||||
|
||||
return res
|
||||
}
|
||||
Reference in New Issue
Block a user