1.算法说明:

如3141592,在m(digitDivide)=100时,即要求计算百位上“1”的个数

其中a为31415,b为92,31415中出现了3142次“1”,因为每10个数里面出现1次“1”。而实际上,31415是3141500,所以把31415中1的个数再乘以m。如3141400~3141499中,前缀为31414的数出现了100次,所以需要乘以m(此时是100)。

class Solution {
public:
int countDigitOne(int n) { int ans=0;
for(long long digitDivide=1;digitDivide<=n;digitDivide*=10)
{
int a=n/digitDivide;
int b=n%digitDivide;
ans+=(a+8)/10*digitDivide+(a%10==1)*(b+1);
}
return ans; }};

Number of Digit One(Medium)的更多相关文章

  1. (medium)LeetCode 233.Number of Digit One

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

  2. [LeetCode] Number of Digit One 数字1的个数

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

  3. [Leetcode] Number of Digit Ones

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

  4. Number of Digit One

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

  5. Java for LeetCode 233 Number of Digit One

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

  6. 233. Number of Digit One *HARD* -- 从1到n的整数中数字1出现的次数

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

  7. 233. Number of Digit One

    题目: Given an integer n, count the total number of digit 1 appearing in all non-negative integers les ...

  8. 【LeetCode】233. Number of Digit One

    题目: Given an integer n, count the total number of digit 1 appearing in all non-negative integers les ...

  9. [Swift]LeetCode233. 数字1的个数 | Number of Digit One

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

随机推荐

  1. CountUp.js 数字跳转效果小插件

    CountUp.js  实现数字跳转效果的小插件 //调用方法 const easingFn = function (t, b, c, d) { var ts = (t /= d) * t; var ...

  2. pywin32获得tkinter窗口句柄,并在上面绘图

    想实现用win32 API在tkinter窗口上画图,那么应该先获得tkinter窗口的句柄hwnd,然后再获得tkinter的设备hdc.尝试了FindWindow(),GetActiveWindo ...

  3. 洛谷P1257(暴力超时)

    1.先输入再求勾股定理会超时 2.需要一边输入一边求. #include<iostream> #include<cmath>#include<cstdio> usi ...

  4. 每天一杯C_Visual Studio各个版本的区别和总结

    细致区别如上图所示 企业版点满图中技能树,能够提供点对点的解决方案,充分满足正规企业的要求. PS:技能最多,肯定也就价格最贵 专业版中提供的专业开发者工具.服务和订阅就成了最佳选择. PS:技能多, ...

  5. 调用支付宝接口的简单demo

    依赖: <!-- alipay-sdk-java 注意一下版本--> <dependency> <groupId>com.alipay.sdk</groupI ...

  6. 操作实践,IDEA自定义toString()方法模板

    声明:迁移自本人CSDN博客https://blog.csdn.net/u013365635 Java POJO在日志中常会用于打印,经常会将POJO的内容全部或部分打印出来,所以POJO类的toSt ...

  7. ArcGIS 二次开发总结

    个人总结 1. Enterprise10.7新特性 新增共享实例,可以将不常用服务分配共享实例,减少服务器压力.仅支持ArcGIS pro发布的地图服务,且仅开启feature access,kml, ...

  8. 1013A.Piles With Stones

    题目出处:http://codeforces.com/contest/1013/problem/A #include<iostream> using namespace std; int ...

  9. CF809C(找规律+数位DP)

    老年选手需要多写一些思维题qwq. 通过打表很容易发现对于(i,j),值为(i-1)^(j-1)+1,然后本题就没了qwq. 矩阵差分还是很容易想到的,容斥成四个矩阵. 然后看到异或很容易想到三件事: ...

  10. NOIP复赛文件路径怎么写

    以2018年NOIP普及组复赛为例,四道题对应着四个文件夹:   随便选一道题,比如第一道题,进入title目录,可以看到title1.in, title1.ans, title2.in, title ...