This commit is contained in:
2022-06-09 15:45:14 +01:00
parent 70fa350da8
commit 14b51882bb
13 changed files with 408 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
package main
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func inorderTraversalInPlace(root *TreeNode, list *[]int) {
if root == nil {
return
}
inorderTraversalInPlace(root.Left, list)
*list = append(*list, root.Val)
inorderTraversalInPlace(root.Right, list)
}
func inorderTraversal(root *TreeNode) []int {
list := &[]int{}
inorderTraversalInPlace(root, list)
return *list
}