✨🚀 Effortlessly 💯 Dominate 100% with Beginner C++ , Java and Python Solution! 🚀✨
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```C++ []\nclass Solution {\npublic:\n    int minChanges(int n, int k) {\n        if (n == k) return 0;\n        bitset<32> a = n, b = k;\n        for (int i = 0; i < 32; ++i) if (b[i] && !a[i]) return -1;\n        int x = 0;\n        for (int i = 0; i < 32; ++i) if (a[i] && !b[i]) x++;\n        return x;\n    }\n};\n```\n```Java []\npublic class Solution {\n    public int minChanges(int n, int k) {\n        if (n == k) return 0;\n        String a = String.format("%32s", Integer.toBinaryString(n)).replace(\' \', \'0\');\n        String b = String.format("%32s", Integer.toBinaryString(k)).replace(\' \', \'0\');\n        for (int i = 0; i < 32; ++i) {\n            if (b.charAt(i) == \'1\' && a.charAt(i) == \'0\') return -1;\n        }\n        int x = 0;\n        for (int i = 0; i < 32; ++i) {\n            if (a.charAt(i) == \'1\' && b.charAt(i) == \'0\') x++;\n        }\n        return x;\n    }\n}\n```\n```Python []\nclass Solution:\n    def minChanges(self, n: int, k: int) -> int:\n        if n == k:\n            return 0\n        a = bin(n)[2:].zfill(32)\n        b = bin(k)[2:].zfill(32)\n        if any(b[i] == \'1\' and a[i] == \'0\' for i in range(32)):\n            return -1\n        x = sum(a[i] == \'1\' and b[i] == \'0\' for i in range(32))\n        return x\n```\n
['C++', 'Java', 'Python3']