Skip to main content

3315. Construct the Minimum Bitwise Array II in F#

Published 1 min readMarkdown

URL

Construct the Minimum Bitwise Array II - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/main/fsharp/leetcode/challenge/202601/construct_the_minimum_bitwise_array2/main.fsx

let minBitwiseArray (nums: int list) : int list =
    let rec f n mask =
        if n &&& mask = 0 then
            n &&& ~~~(mask >>> 1)
        else
            f n (mask <<< 1)

    nums |> List.map (fun n -> if n % 2 = 0 then -1 else f n 1)

No comments yet. Be the first to comment.