2729. Check if The Number is Fascinating ¶ Time: $O(1)$ Space: $O(1)$ C++JavaPython 1 2 3 4 5 6 7 8class Solution { public: bool isFascinating(int n) { string s = to_string(n) + to_string(2 * n) + to_string(3 * n); ranges::sort(s); return s == "123456789"; } }; 1 2 3 4 5 6 7 8class Solution { public boolean isFascinating(int n) { String s = Integer.toString(n) + Integer.toString(2 * n) + Integer.toString(3 * n); char[] charArray = s.toCharArray(); Arrays.sort(charArray); return new String(charArray).equals("123456789"); } } 1 2 3 4class Solution: def isFascinating(self, n): s = str(n) + str(2 * n) + str(3 * n) return ''.join(sorted(s)) == '123456789'