// brute force, time : O(n*logn), n is the max input, space: O(1)classSolution {publicintnextBeautifulNumber(int n) {while (true) { n++;if (isValid(n)) {return n; } } }privatebooleanisValid(int n) {int count[] =newint[10];while (n !=0) {if (n %10==0) { // in this problem, the ans wont has 0 in each single digits, 0 cant appear 0 timereturnfalse; } count[n%10]++; // count digits' number n /=10; }for (int i =1; i <10; i++) {if (count[i] !=0&& count[i] != i) { // as problem discription, digit i occurs i timesreturnfalse; } }returntrue; }}/*> nstart from n to find beauti numberBrute force*/j