count digit one
来源:互联网 发布:k线图基础知识 知乎 编辑:程序博客网 时间:2024/05/14 16:51
class Solution {
public:
int countDigitOne(int n) {
if(n<=0) return 0;
if(n<10) return 1;
long factor=1;
while(factor*10<=n)
factor*=10;
int top=n/factor;
// cout<<top<<endl;
if(top==1) return countDigitOne(factor-1)(前面的)+countDigitOne(n%factor)(剩下的)+n%factor(最前面一位是1,因此余数的每一个都含有一个1)+1;
else return top*countDigitOne(factor-1)(分开求每一部分的)+countDigitOne(n%factor)+factor(加上第一位是1的);
}
};
public:
int countDigitOne(int n) {
if(n<=0) return 0;
if(n<10) return 1;
long factor=1;
while(factor*10<=n)
factor*=10;
int top=n/factor;
// cout<<top<<endl;
if(top==1) return countDigitOne(factor-1)(前面的)+countDigitOne(n%factor)(剩下的)+n%factor(最前面一位是1,因此余数的每一个都含有一个1)+1;
else return top*countDigitOne(factor-1)(分开求每一部分的)+countDigitOne(n%factor)+factor(加上第一位是1的);
}
};
0 0
- LeetCode -- Count Digit One
- count digit one
- 4315. Digit Count
- LightOJ 1122 - Digit Count
- LightOJ 1122 - Digit Count
- Sicily 4315. Digit Count
- lightoj 1122 Digit Count
- 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
- skynet框架 源码分析 二
- 关于form提交表单和onclick事件的触发
- Android 热修复三部曲之基本的Ant打包脚本
- This version of Android Studio is incompatible with the Gradle Plugin used
- myeclipse10破解中 run.bat 闪退
- count digit one
- spacemacs中用graphviz绘制decision tree
- 一文看懂大数据的技术生态圈,Hadoop,hive,spark都有了
- Android热修复三部曲之MultiDex 分包架构
- 大学第一个国庆长假做了啥?
- 容器类和接口框架
- 使用Google Protocol Bufffers进行通信(Ruby & ObjC & Java)
- 丑数 java
- Codeforces Round #337 (Div. 2)-B. Vika and Squares