C++ || 2 different approaches || O(1) TC
Approach 1: do the work at compile time\nThe property of being fascinating doesn\'t change, hence we can pre compute them at compile time. ::isFascinating is in
# Approach 1: do the work at compile time\nThe property of being _fascinating_ doesn\'t change, hence we can pre compute them at compile time. ```::isFascinating``` is inspired by [this post](https://leetcode.com/problems/check-if-the-number-is-fascinating/discuss/3622454/Bits-(O(1)-Space)).\n\n```cpp\nnamespace {\nconstexpr bool isFascinating(int n) {\n    int seen = 0;\n    auto check = [&](int n) -> bool {\n        while (n) {\n            const int d =  n % 10;\n            n /= 10;\n            const int mask = 1 << d;\n            if (d == 0 || seen & mask) return false;\n            seen |= mask;\n        }\n        return true;\n    };\n    return check(n) && check(2 * n) && check(3 * n);\n}\n\nconstexpr array<bool, 1000> gen_isF() {\n    array<bool, 1000> ans = {};\n    for (int i = 100; i < 1000; ++i) \n        ans[i] = isFascinating(i);\n    return ans;\n}\n    \nconstexpr array<bool, 1000> isF = gen_isF();\n}  // namespace\n\nclass Solution {\npublic:\n    static bool isFascinating(int n) {\n        return isF[n];\n    }\n};\n```\n\n**Complexity Analysis**\n* Time complexity is $$O(1)$$ and\n\n* Space comlexity is $$O(1)$$, even if we need to keep an array of 1000 booleans around.\n\n# Approach 2: hard code it\nIt turns out there are only 4 _fascinating_ numbers: 192, 219, 273, and 327. We can just hard code that. Maybe that\'s consider cheating. :)\n\n```cpp\n    bool isFascinating(int n) {\n        return n == 192 || n == 219 || n == 273 || n == 327;\n    }\n```\n\nIt\'s interesting how the compiler generates something that looks like binary search for this: https://godbolt.org/z/P9cr7fnE9\n\n**Complexity Analysis**\n* Time complexity is $$O(1)$$ and\n\n* Space comlexity is $$O(1)$$.\n\n_As always: Feedback, questions, and comments are welcome. Leaving an up-vote sparks joy! :)_\n\n**p.s. Join us on the [LeetCode The Hard Way Discord Server](https://discord.gg/hFUyVyWy2E)!**
['C']