This makes much more sense instead of % 2 we can use &1 which return 1 if bit is 1 and 0 when bit is 0; and we can right shift num by 1 class Solution { public: vector countBits(int n) { vector ans; for(int i=0;i>1; } ans.push_back(sum); } return ans; } };
how diving the num by 2 removing 1 value from the unit place i think it's done by dividing it by 10 1011/2 = 505 1011/10 = 101 and that's what we want here