Skip to main content

LeetCode 1317. Convert Integer to the Sum of Two No-Zero Integers in F#

Published 1 min readMarkdown

URL

Convert Integer to the Sum of Two No-Zero Integers - LeetCode

Code

dotnet-study/fsharp/leetcode/challenge/202509/convert_integer_to_the_sum_of_two_no_zero_integers/main.fsx at master · syohex/dotnet-study

let getNoZeroIntegers (n: int) : int * int =
    let isNoZeroInteger n = string n |> Seq.forall ((<>) '0')

    let rec getNoZeroIntegers' a =
        if a = n then
            failwith "never reach here"
        else
            let b = n - a

            if isNoZeroInteger a && isNoZeroInteger b then
                a, b
            else
                getNoZeroIntegers' (a + 1)

    getNoZeroIntegers' 1

No comments yet. Be the first to comment.

More from this blog