LeetCode 104. Maximum Depth of Binary Tree in F#
LeetCode Daily Program at 2022/02/14
Shohei Yoshida
2 years ago | 1 min read
URL
https://leetcode.com/problems/maximum-depth-of-binary-tree/
Code
https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/problems/0104/main.fsx
type Tree =
| Leaf
| TreeNode of int * Tree * Tree
let rec maxDepth (r: Tree) : int =
match r with
| Leaf -> 0
| TreeNode (_, left, right) -> (max (maxDepth left) (maxDepth right)) + 1
Upvote
Created by
Shohei Yoshida
A Programmer
Post
Related Articles