Skip to content

Commit bbcfae1

Browse files
committed
feat: add question 233
1 parent b40c224 commit bbcfae1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

233.数字-1-的个数.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* @lc app=leetcode.cn id=233 lang=javascript
3+
*
4+
* [233] 数字 1 的个数
5+
*/
6+
7+
// @lc code=start
8+
/**
9+
* @param {number} n
10+
* @return {number}
11+
*/
12+
var countDigitOne = function(n) {
13+
let result = 0;
14+
for (let i = 1; i <= n; i *= 10) {
15+
const div = i * 10;
16+
result += Math.floor(n / div) * i + Math.min(Math.max(n % div - i + 1, 0), i);
17+
}
18+
19+
return result;
20+
};
21+
// @lc code=end

0 commit comments

Comments
 (0)