Java Digital DP
java\nclass Solution {\n    public int numDupDigitsAtMostN(int N) {\n        int[] digits = new int[10];\n        int pos = 0, temp = N;\n        while (N > 0) 
```java\nclass Solution {\n    public int numDupDigitsAtMostN(int N) {\n        int[] digits = new int[10];\n        int pos = 0, temp = N;\n        while (N > 0) {\n            digits[pos++] = N % 10;\n            N /= 10;\n        }\n        return temp - dfs(digits, pos - 1, 0, new int[10][1 << 10], true) + 1;\n    }\n    \n    public int dfs(int[] digits, int pos, int pre, int[][] dp, boolean limit) {\n        if (pos == -1) return 1;\n        if (!limit && dp[pos][pre] != 0) return dp[pos][pre];\n        int up = limit ? digits[pos] : 9;\n        int ans = 0;\n        for (int i = 0; i <= up; i++) {\n            if ((pre & (1 << i)) != 0 && (pre != 0 || i != 0)) continue;\n            if (pre == 0 && i == 0) {\n                ans += dfs(digits, pos - 1, pre, dp, limit && i == up);\n            } else {\n                ans += dfs(digits, pos - 1, pre ^ (1 << i), dp, limit && i == up);\n            }\n        }\n        if (!limit) dp[pos][pre] = ans;\n        return ans;\n    }\n}\n```
[]