cft

LeetCode 104. Maximum Depth of Binary Tree in F#

LeetCode Daily Program at 2022/02/14


user

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


user
Created by

Shohei Yoshida

A Programmer


people
Post

Upvote

Downvote

Comment

Bookmark

Share


Related Articles