Created
October 28, 2017 12:26
-
-
Save scriptnull/10650eb704922fb136853d1fb5214bc1 to your computer and use it in GitHub Desktop.
Inorder Traversal in binary tree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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