Shohei Yoshida
Shohei Yoshida's Blog

Follow

Shohei Yoshida's Blog

Follow

LeetCode 70. Climbing Stairs in F#

Shohei Yoshida's photo
Shohei Yoshida
·Dec 12, 2022·

1 min read

URL

leetcode.com/problems/climbing-stairs/descr..

Code

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

let climbStairs (n: int) : int =
    let rec climbStairs' m n prev2 prev1 =
        if m = n then
            prev1 + prev2
        else
            climbStairs' (m + 1) n prev1 (prev1 + prev2)

    match n with
    | 1 -> 1
    | 2 -> 2
    | _ -> climbStairs' 3 n 1 2
 
Share this