@menglin0320 According to @fengcc, i&(i-1) drops the lowest set bit, e.g. 1 bit. So if you think twice, what is the difference between i&(i - 1) and i, in terms of the count of 1? Just 1 occurrence of 1, right?

Another method works as follows:

[0] -> [1]: add 1 in front

[0, 1] -> [2, 3]: add 1 in front

[0, 1, 2, 3] -> [4, 5, 6, 7]: add 1 in front

This is not exactly "one single pass" of the array, but the number of visited elements is the same. If you write down the binary numbers from 0 to 8 in a column, you find find out easily.