233 Number of Digit One
这道题是递归算法
class Solution: # @param {integer} n # @return {integer} def countDigitOne(self, n): if n <= 0: return 0 if n < 10: return 1 s = str(n) ls = len(s) ans = 0 if s[0] == "1": ans += int(s[1:]) + 1 + pow(10, ls-2) * (ls-1) ans += self.countDigitOne(int(s[1:])) else: ans += int(s[0]) * pow(10, ls-2) * (ls-1) + pow(10, ls-1) ans += self.countDigitOne(int(s[1:])) return ans