# Number of Digit One

public class Solution {
public int countDigitOne(int n) {
int result = 0;
for (long m = 1; m <= n; m *= 10) {
long left = n / m;
long right = n % m;
result += (left + 8) / 10 * m;
if (left % 10 == 1) {
result += right + 1;
}
}
return result;
}
}

• 本文已收录于以下专栏：

## leetcode -- Number of Digit One -- 数学题，找规律

https://leetcode.com/problems/number-of-digit-one/参考http://www.cnblogs.com/grandyang/p/4629032.htmlh...
• xyqzki
• 2015年12月16日 17:11
• 268

## LeetCode-233.Number of Digit One

https://leetcode.com/problems/number-of-digit-one/ Given an integer n, count the total number o...

## LeetCode No.233 Number of Digit One

LeetCode No.233 Number of Digit One

## leetcode解题笔记：Number of Digit One

233.Number of Digit One Given an integer n, count the total number of digit 1 appearing in all non...

## ［分析总结：leetcode-Number of Digit One]寻找整数1到n之间所有数字中1出现的次数

leetcode原题链接：https://leetcode.com/problems/number-of-digit-one/ 题目描述： 要求寻找整数1到n之间所有数字中，1出现的次数。如给定...

## Leetcode Number of Digit One

Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th...

## [LeetCode]Number of Digit One,解题报告

举报原因： 您举报文章：Number of Digit One 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)