Math，O(logN)
Count the number without repeated digit.\nwe start with the highest bit of N, if N is 1000,  the highest bit must less than 1, so we start with 0,\nthe biggest 
Count the number without repeated digit.\nwe start with the highest bit of N, if N is 1000,  the highest bit must less than 1, so we start with 0,\nthe biggest number without repeated dight is 999, the leghth is 3.\nthe highest bit can be 1~9 ( we count numbers start with 0 later) ,  the second bit can be 0~9, excluding that is the same with the previous bits... and so on.\nthe total number is 9*(10-1)*(10-2)+count(2,9) ( if the second bit is 0, we consider it as a new number whose lenght is 2)\n\n```\npublic int numDupDigitsAtMostN(int N) {\n        int n=N;\n        int count=0;\n        int[] arr=new int[11];\n        while (n>0) {\n            arr[++count]=n%10;\n            n/=10;\n        }\n        int res=count(count, arr[count]-1);\n        Set<Integer> set=new HashSet<>(10);\n        set.add(arr[count]);\n        for (int i = count-1; i >0; i--) {\n            int maxcur=arr[i], rems=0;\n            while (maxcur>=0 && set.contains(maxcur))\n                maxcur--;\n            if(maxcur<0) break;\n            set.add(maxcur);\n            int bit=maxcur-1;\n            while (bit>=0){\n                if(!set.contains(bit)) rems++;\n                bit--;\n            }\n            if(maxcur<arr[i]) rems++;\n            int cnt=rems;\n            for (int j = 1; j < i; j++) {\n                cnt*=(10-(count-i)-j);\n            }\n            res+=cnt;\n            if(maxcur<arr[i]) {\n                set.remove(maxcur);\n                break;\n            }\n            arr[i]=maxcur;\n        }\n        if(set.size()==count) res+=1;\n        return N-res;\n    }\n\t//count the number  without repeated digit and the highest less than num, the lenght is n\n    public int count(int n, int num){\n        if(n<1) return 0;\n        if(n==1) return num;\n        int count=0, N=n;\n\t\t//the highest bit isn\'t 0\n        if(num>0) {\n            count=num;\n            while (--n > 0) {\n                count *= (10 - n);\n            }\n        }\n\t\t//if the highest bit is 0\n        count+=count(N-1, 9);\n        return count;\n    }\n```
[]