- # -*- coding:utf-8 -*-
- class Solution:
- def NumberOf1Between1AndN_Solution(self, n):
- count = 0
- for item in range(1,n+1):
- pstr = str(item)
- count += pstr.count('1')
- return count
- #该片段来自于http://www.codesnippet.cn/detail/0501201614365.html
来源: http://www.codesnippet.cn/detail/0501201614365.html