Shohei Yoshida
Shohei Yoshida's Blog

Follow

Shohei Yoshida's Blog

Follow

LeetCode 263. Ugly Number in F#

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

1 min read

URL

leetcode.com/problems/ugly-number

Code

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

let isUgly (n: int) : bool =
    let rec div divisor (n: int) =
        if n % divisor <> 0 then
            n
        else
            div divisor (n / divisor)

    if n <= 0 then
        false
    else
        (n |> div 2 |> div 3 |> div 5) = 1
 
Share this