C# - 3 lines - O(highest set bit)
\nthe complexity will be the number of digits up to the highest set bit.\n\n\n    public int FindComplement(int num) \n    {\n        int mask = 1;\n        whi
\nthe complexity will be the number of digits up to the highest set bit.\n\n```\n    public int FindComplement(int num) \n    {\n        int mask = 1;\n        while (mask < num) mask = (mask << 1) | 1;\n        return ~num & mask;\n    }\n```
[]