LeetCode 94. Binary Tree Inorder Traversal in F#
URL
leetcode.com/problems/binary-tree-inorder-t..
Code
github.com/syohex/dotnet-study/blob/master/..
type Tree =
| Leaf
| Node of int * Tree * Tree
let inorderTraversal (root: Tree) : int list =
let rec inorderTraversal' node acc =
match node with
| Leaf -> acc
| Node (v, left, right) ->
let acc' = inorderTraversal' left acc
let acc'' = v :: acc'
inorderTraversal' right acc''
inorderTraversal' root [] |> List.rev