其他分享
首页 > 其他分享> > Leetcode: Numbers With Repeated Digits

Leetcode: Numbers With Repeated Digits

作者:互联网

description

Given a positive integer N, return the number of positive integers less than or equal to N that have at least 1 repeated digit.

Example

Input: 1000
Output: 262

分析


count = 0
dup = ['00', '11', '22', '33', '44', '55', '66', '77', '88', '99']

for i in range(1, 1001):
    s = str(i)
    for j in dup:
        if j in s:
            count += 1
            break
print(count)  ==> 181

运行这段代码可以看出 小于等于 1000 的整个数是 181, 不是 262 

总结

标签:Digits,count,ac,positive,262,Repeated,181,dup,Leetcode
来源: https://www.cnblogs.com/tmortred/p/13191433.html