标签:between 1出现的次数 问题 width question def png color value
highValue == 0 退出
1 # -*- coding:utf-8 -*- 2 class Solution: 3 def NumberOf1Between1AndN_Solution(self, n): 4 # write code here 5 precise = 1 6 lowValue = 1 7 highValue=1 8 midValue=1 9 sumNum = 0 10 num = 0 11 count = 0 12 while highValue!=0: 13 highValue = n // (precise*10) 14 midValue = n // (precise) % 10 15 lowValue = n % (precise) 16 precise = precise*10 17 18 if midValue == 0: 19 num = (highValue-1+1)*pow(10,count) 20 elif midValue > 1: 21 num = (highValue+1)*pow(10,count) 22 else: 23 num = highValue*pow(10,count)+lowValue+1 24 sumNum += num 25 count += 1 26 return sumNum
2019-12-21 21:07:12
标签:between 1出现的次数 问题 width question def png color value
原文地址:https://www.cnblogs.com/NPC-assange/p/12078239.html