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 发布文章使用:只允许注册用户才可以访问!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13675927.html
未经授权禁止转载,违者必究!