We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3a2a0ba commit 7d586dbCopy full SHA for 7d586db
233-number-of-digit-one.js
@@ -1,3 +1,33 @@
1
+/**
2
+ * @param {number} n
3
+ * @return {number}
4
+ */
5
+const countDigitOne = function(n) {
6
+ let res = 0
7
+ const s = `${n}`
8
+ const len = s.length, {floor, pow} = Math
9
+
10
+ for(let i = 1; i <= len; i++) {
11
+ const np = pow(10, i - 1)
12
+ const pre = floor(n / pow(10, i))
13
+ const remain = n % np
14
15
+ res += pre * np
16
+ const e = +s[len - i]
17
+ if(e > 1) {
18
+ res += np
19
+ } else if(e === 1) {
20
+ res += remain + 1
21
+ }
22
23
24
+ return res
25
+};
26
27
28
+// another
29
30
31
/**
32
* @param {number} n
33
* @return {number}
0 commit comments