cft
Become a CreatorSign inGet Started

LeetCode 104. Maximum Depth of Binary Tree in F#

LeetCode Daily Program at 2022/02/14


user

Shohei Yoshida

3 months ago | 1 min read
Follow

leetcode-104-maximum-depth-binary-tree-gdah2

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

Follow

A programmer of DeNA

A Programmer


people
Post

Upvote

Downvote

Comment

Bookmark

Share


Related Articles