把整数转换为字符串
用count计数
1 # -*- coding:utf-8 -*- 2 class Solution: 3 def NumberOf1Between1AndN_Solution(self, n): 4 # write code here 5 count = 0 6 for i in range(1,n+1): 7 s = str(i) 8 count += s.count('1') 9 return count 10