Shohei Yoshida
Shohei Yoshida's Blog

Follow

Shohei Yoshida's Blog

Follow

LeetCode 222. Count Complete Tree Nodes in F#

Shohei Yoshida's photo
Shohei Yoshida
·Nov 15, 2022·

1 min read

URL

leetcode.com/problems/count-complete-tree-n..

Code

github.com/syohex/dotnet-study/blob/master/..

type Tree =
    | Leaf
    | Node of int * Tree * Tree

let rec countNodes (root: Tree) : int =
    match root with
    | Leaf -> 0
    | Node (_, left, right) -> 1 + countNodes left + countNodes right
 
Share this