Java Solution || Using For Loop
Intuition\n Describe your first thoughts on how to solve this problem. \nWe are given a number n, we need to check whether every digit from 1 to 9 is present in
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe are given a number n, we need to check whether every digit from 1 to 9 is present in the number which is formed connecting n + 2 * n + 3 * n.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIn the code we have made a string s, in which we have stored the number n, 2 * n and 3 * n in string format. We then have created a array of size 9 containing all elements equal to 1. We then ran a for loop till the length of string and checking the value of element at the index (s.charAt(i) - \'0\') - 1 if it is equal to 1 then changing it to zero and if already equal to 0 then returning false which means a number is repeated in the string. And also checking that (s.charAt(i) - \'0\') - 1 should be greater than 0 because if less than 0 will give a error as there is no index -1 or less in the array.\n\n# Code\n```\nclass Solution {\n    public boolean isFascinating(int n) {\n\n        String s = String.valueOf(n) + String.valueOf(2*n) + String.valueOf(3*n);\n\n        int[] arr = new int[9];\n        Arrays.fill(arr,1);\n\n        for(int i=0;i<s.length();i++){\n            int j = s.charAt(i) - \'0\';\n            if(j-1<0){\n                return false;\n            }\n            if(arr[j-1] == 0){\n                return false;\n            }else{\n                arr[j-1] = 0;\n            }\n        }\n\n        for(int i=0;i<arr.length;i++){\n            if(arr[i]!=0){\n                return false;\n            }\n        }\n\n        return true;\n\n    }\n}\n```\n\n![oie_CksRiTNvbciG.jpg](https://assets.leetcode.com/users/images/96683108-fa6b-4899-825c-6216059f5ff0_1689172819.995048.jpeg)
['Java']