Leet Code 191. Number of 1 Bits in F#

URL

Number of 1 Bits - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/challenge/202311/number_of_1bits/main.fsx

let hammingWeight (n: uint32) : int =
    let rec hammingWeight' (n: uint32) acc =
        if n = 0u then
            int acc
        else
            hammingWeight' (n >>> 1) (acc + (n &&& 1u))

    hammingWeight' n 0u