xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

C++ 0LL

C++ 0LL

C plus plus

L / l means long

LL === long long

int countDigitOne(int n) {
    int countr = 0;
    for (long long i = 1; i <= n; i *= 10) {
        long long divider = i * 10;
        countr += (n / divider) * i + min(max(n % divider - i + 1, 0LL), i);
    }
    return countr;
}

LeetCode


/**
 * @param {number} n
 * @return {number}
 */
var countDigitOne = function(n) {
   let count = 0;
   for (let i = 1; i <= n; i *= 10) {
        let divider = i * 10;
        count += ((n / divider) * i) + Math.min(Math.max(n % divider - i + 1, 0), i);
    }
    return count;
};

https://leetcode.com/problems/number-of-digit-one/solution/

refs

https://stackoverflow.com/questions/7036056/what-do-0ll-or-0x0ul-mean



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


posted @ 2020-09-15 22:04  xgqfrms  阅读(2435)  评论(0编辑  收藏  举报