JAVA | 2 solutions | Easy ✅
Solution 1:\n\nclass Solution {\n    public int[] evenOddBit(int n) {\n        String s = Integer.toBinaryString(n);\n        int even = 0, odd = 0;\n        fo
# Solution 1:\n```\nclass Solution {\n    public int[] evenOddBit(int n) {\n        String s = Integer.toBinaryString(n);\n        int even = 0, odd = 0;\n        for (int i = s.length() - 1; i >= 0; i--) {\n            int idx = s.length() - i - 1;\n            if (s.charAt(i) == \'1\') {\n                if (idx % 2 == 0) even++;\n                else odd++;\n            }\n        }\n        \n        return new int[] {even, odd};\n    }\n}\n```\n##### Time complexity: $$O(32) => O(1)$$\n##### Space complexity: $$O(32) => O(1)$$\n---\n# Solution 2:\n```\nclass Solution {\n    public int[] evenOddBit(int n) {\n        int idx = 0;\n        int even = 0, odd = 0;\n        while (n > 0) {\n            if ((n & 1) == 1) {\n                if (idx % 2 == 0) even++;\n                else odd++;\n            }\n            n >>= 1;\n            idx++;\n        }\n        \n        return new int[] {even, odd};\n    }\n}\n```\n##### Time complexity: $$O(32) => O(1)$$\n##### Space complexity: $$O(1)$$
['Bit Manipulation', 'Java']