[Python3] Simple solutions with explanation (string, bit manipulation)
The logic behind is based on the observation that the least significant group of ones can be determined by checking whether the least significant bit of n is a
The logic behind is based on the observation that the least significant group of ones can be determined by checking whether the least significant bit of n is a '1' or a '0'. Similarly, the next group of ones can be determined by checking the second least significant bit, and so on.
We count adjacent groups of ones, starting from the most significant bit to the least significant bit. If the current index is even and the value is '1', increment the first element of the list, otherwise, if the current index is odd and the value is also '1', increment the second element of the list.
```python []
class Solution:
    def evenOddBit(self, n: int) -> List[int]:
        ans = [0, 0]
        
        for idx, val in enumerate(bin(n)[2:][::-1]):
            if idx % 2 == 0 and val == '1':
                ans[0] += 1
            elif idx % 2 == 1 and val == '1':
                ans[1] += 1
                
        return ans
```
Same story, but now with bitwise operations. Inside the while loop, we add the least significant bit of **n** to the appropriate element in the list based on the value of **i**: if i == 0, we add the least significant bit to the first element of the list, otherwise, we add it to the second element of the list. Next, we **right shift** n by one bit, removes the least significant bit of n. Finally, we use **XOR** i with 1 to flips the value of i between 0 and 1.
```python []
class Solution:
    def evenOddBit(self, n: int) -> List[int]:
        ans = [0, 0]
        i = 0
        
        while n:
            ans[i] += n & 1
            n >>= 1
            i ^= 1

        return ans
```
['Bit Manipulation', 'Python', 'Python3']