Shohei Yoshida
Shohei Yoshida's Blog

Shohei Yoshida's Blog

LeetCode 326. Power of Three in F#

Shohei Yoshida's photo
Shohei Yoshida
·Aug 24, 2022·

1 min read

URL

leetcode.com/problems/power-of-three

Code

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

let isPowerOfThree (n: int) : bool =
    let rec isPowerOfThree' (v: int64) (n: int64) (limit: int64) =
        if v > limit then false
        elif n = v then true
        else isPowerOfThree' (v * 3L) n limit

    let limit = System.Int32.MaxValue |> int64
    isPowerOfThree' 1L (n |> int64) limit
 
Share this