Skip to content

Commit 54cd41e

Browse files
committed
Runtime: 59 ms (Top 97.10%) | Memory: 42.1 MB (Top 56.52%)
1 parent 0200775 commit 54cd41e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// Runtime: 59 ms (Top 97.10%) | Memory: 42.1 MB (Top 56.52%)
12
var countDigitOne = function(n) {
23
if(n <= 0) return 0;
34
if(n < 10) return 1;
45
var base = Math.pow(10, n.toString().length - 1);
56
var answer = parseInt(n / base);
67
return countDigitOne(base - 1) * answer + (answer === 1 ? (n - base + 1) : base) + countDigitOne(n % base);
7-
};
8+
};

0 commit comments

Comments
 (0)