Counting Even and Odd Bits in an Integer
Intuition\n\nThe code seems to aim at counting the occurrence of even and odd bits in the binary representation of a given integer.\n\n# Approach\nThe approach 
# Intuition\n\nThe code seems to aim at counting the occurrence of even and odd bits in the binary representation of a given integer.\n\n# Approach\nThe approach in the code is to convert the given integer into its binary representation and then count the occurrences of even and odd bits.\n\n1. Convert the given integer into its binary representation by repeatedly dividing it by 2 and recording the remainders.\n2.  Count the occurrences of even and odd bits in the binary representation.\n3. Return the counts.\n\n# Complexity\n- Time complexity: O(log n).\n\n- Space complexity: O(log n)\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> evenOddBit(int n) {\n        string ans = "";\n        while(n != 0){\n            if(n%2 != 0){\n                ans += \'1\';\n            }\n            else{\n                ans += \'0\';\n            }\n            n = n/2;\n        }\n\n        int evenCnt = 0;\n        int oddCnt = 0;\n\n        for(int i = 0; i < ans.length(); i++){\n            if((i % 2 == 0) && ans[i] == \'1\'){\n                evenCnt++;\n            }\n            else if( i % 2 != 0 && ans[i] == \'1\'){\n                oddCnt++;\n            }\n        }\n\n        return { evenCnt, oddCnt};\n    }\n};\n```
['C++']