Efficient Java Solution
Intuition\n Describe your first thoughts on how to solve this problem. \nMy initial thought was to check if a number n is "fascinating" by verifying that the co
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nMy initial thought was to check if a number n is "fascinating" by verifying that the concatenation of n, 2\xD7n and 3 \xD7 \uD835\uDC5B contains exactly the digits 1 through 9 with no zeros or repetitions. If this combined number meets these conditions, then n is fascinating.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Compute Multiples: Calculate 2\xD7n and 3 \xD7 \uD835\uDC5B\n\n- Digit Extraction: Using three loops, I individually extract each digit from n, 2\xD7n and 3 \xD7 \uD835\uDC5B.\n\n- I use modulo and division to isolate each digit and check if it\'s zero or if it has already been seen.\n\n- If the digit is zero or already in the set, return false.\n\n- If it\u2019s a valid, unique digit, add it to a HashSet to keep track.\n\n- Final Check: After processing all digits, check if the HashSet contains exactly 9 digits, indicating we have every digit from 1 to 9 exactly once. If so, return true; otherwise, return false.\n\n- This approach efficiently checks each digit for uniqueness and excludes any invalid cases like zeros or duplicates.\n\n# Complexity\n- Time complexity: log(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public boolean isFascinating(int n) {\n        int a = 2*n;\n        int b = 3*n;\n        HashSet<Integer> hs = new HashSet<>();\n        while(a != 0){\n           int r = a % 10;\n           if(r==0 || hs.contains(r)){\n               return false;\n           }\n           hs.add(r);\n           a/=10;\n        }\n        while(b != 0){\n           int r = b % 10;\n           if(r==0 || hs.contains(r)){\n               return false;\n           }\n           hs.add(r);\n           b/=10;\n        }\n        while(n != 0){\n           int r = n % 10;\n           if(r==0 || hs.contains(r)){\n               return false;\n           }\n           hs.add(r);\n           n/=10;\n        }\n    return hs.size() == 9;\n    }\n}\n```
['Java']