Number of Digit One(数学找规律)
来源:互联网 发布:java api 1.8中文在线 编辑:程序博客网 时间:2024/06/05 03:51
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.
For example:
Given n = 13,
Return 6, because digit 1 occurred in the following numbers: 1, 10, 11, 12, 13.
public class Solution { public int countDigitOne(int n) { int ones = 0; for (long m = 1; m <= n; m *= 10) ones += (n/m + 8) / 10 * m + (n/m % 10 == 1 ? n%m + 1 : 0); return ones; }}
http://www.cnblogs.com/aniy/articles/4676538.html
http://blog.csdn.net/xudli/article/details/46798619
http://blog.csdn.net/wangyunyun00/article/details/47342983
https://leetcode.com/discuss/44281/4-lines-o-log-n-c-java-python
0 0
- Number of Digit One(数学找规律)
- leetcode -- Number of Digit One -- 数学题,找规律
- leetcode:数学:Number of Digit One(233)
- Number of Digit One
- Number of Digit One
- Number of Digit One
- Number of Digit One
- Number of Digit One
- Number of Digit One
- Number of Digit One
- Number of Digit One
- Number of Digit One
- Number of Digit One
- Number of Digit One
- Number of Digit One
- Number of Digit One
- Number of Digit One
- 数学找规律 number
- 正则表达式语法
- link rel=canonical 用法
- 压缩JS代码
- 以代码为实例讲解sizeof函数易混淆的用法
- Ugly Number II
- Number of Digit One(数学找规律)
- Linux上快速启动一个HTTP server
- java 单一登录
- JS监听关闭浏览器事件
- [Index]Search in Rotated Sorted Array series
- [Index]ZigZag Conversion
- Android Api Demos登顶之路(七十七)Graphics-->FingerPaint
- LeetCode 题解(224) : Merge Sorted Array
- LeetCode-Partition List