Shohei Yoshida
Shohei Yoshida's Blog

Follow

Shohei Yoshida's Blog

Follow

LeetCode 198. House Robber in F#

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

1 min read

URL

House Robber - LeetCode

Code

let rob (nums: int list) : int =
    let rec rob' (nums: int list) prev2 prev1 =
        match nums with
        | [] -> prev1
        | h :: t ->
            let prev1' = System.Math.Max(prev1, prev2 + h)
            rob' t prev1 prev1'

    rob' nums 0 0
 
Share this