python easy follow
the basic idea here is computing the non-repeat numbers first and then use N minus the non-repeat numbers.\nsuppose N is abcde, compute non- repeat numbers smal
the basic idea here is computing the non-repeat numbers first and then use N minus the non-repeat numbers.\nsuppose N is abcde, compute non- repeat numbers smaller than a0000. then compute non-repeat number between a0000 and ab000, and so on.\n\n\'\'\'\n\n\tdef numDupDigitsAtMostN(self, N: int) -> int:\n        def helper(s):\n            non_repeat = 0\n            carry = set()\n            for i in range(len(s)-1):\n                if s[i] in carry:\n                    return non_repeat\n                carry.add(s[i])\n                tem = int(s[i+1])\n                for _ in range(int(s[i+1])):\n                    if str(_) in carry:\n                          tem -= 1\n                tem = max(tem, 0)\n                for j in range(i+2, len(s)):\n                    tem *= (10-j)\n                non_repeat += tem\n            return non_repeat + (s[-1] not in carry)\n        num = str(N)\n        non_repeat = 0\n\t\t# compute non- repeat numbers smaller than a0000\n        for l in range(1, len(num) + 1):\n            if l == len(num):\n                 pre, i = int(num[0]) -1, 1\n            else:\n                pre, i = 9, 1\n            while i < l:\n                pre *= (10 - i)\n                i += 1\n            non_repeat += pre        \n        return N - non_repeat - helper(num)\n\'\'\'
[]