Rust Day 18: Leetcode — Number of 1 Bit

Arjun Sunil Kumar
Go Rust
Published in
2 min readMay 8, 2022

Today, I moved out to a new place. The entire day was spent mostly shifting. Couldn’t focus much on the DB side of things. Anyways, completing the LC streak.

This is a well-known problem called hamming distance.

Problem:

Logic:

Logic 1

The above logic is used in the Fenwick tree.

Logic 2

This is more like scanning every 32 bits of the integer and checking if it is set to 1 or not.

Code:

Syntax:

  1. for i in 0..32 : for loop syntax
  2. (n&1) as i32: gets the last bit and casts it to i32 for adding it.

Reference:

Found it Interesting?

Please show your support by 👏

--

--

Arjun Sunil Kumar
Go Rust

Writes on Database Kernel, Distributed Systems, Cloud Technology, Data Engineering & SDE Paradigm. github.com/arjunsk