catch-up
This commit is contained in:
30
binary-tree-inorder-traversal/sol.go
Normal file
30
binary-tree-inorder-traversal/sol.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user