Skip to content

Instantly share code, notes, and snippets.

@scriptnull
Created October 28, 2017 12:26
Show Gist options
  • Select an option

  • Save scriptnull/10650eb704922fb136853d1fb5214bc1 to your computer and use it in GitHub Desktop.

Select an option

Save scriptnull/10650eb704922fb136853d1fb5214bc1 to your computer and use it in GitHub Desktop.
Inorder Traversal in binary tree.
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func inorderTraversal(root *TreeNode) []int {
var result []int
if root == nil {
return result
}
left := inorderTraversal(root.Left)
result = append(result, left...)
result = append(result, root.Val)
right := inorderTraversal(root.Right)
result = append(result, right...)
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment