标签:
def q32(n, len): if n < 0: return 0 elif n <= 1: return n total = 0 while n > 0: if n >= 1 and n < 10: total += 1 return total p1 = n % (10**(len - 1)) h = n / (10**(len - 1)) p2 = p1 + 1 n = p1 if h > 1: total += 10**(len - 1) else: total += p2 total += 10 **(len -2) * h * (len - 1) return total
版权声明:本文博客原创文章。博客,未经同意,不得转载。
【剑指offer】Q32:从1至n整1出现的次数(python)
标签:
原文地址:http://www.cnblogs.com/mengfanrong/p/4680806.html