Skip to content

Commit a2fe75a

Browse files
authored
Update 400-nth-digit.js
1 parent 8b0eeba commit a2fe75a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

400-nth-digit.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
* @return {number}
44
*/
55
const findNthDigit = function(n) {
6-
let start = 1
7-
let len = 1
8-
let base = 9
9-
while(n > len * base) {
10-
n = n - len * base
11-
len++
12-
start *= 10
13-
base *= 10
14-
}
15-
let target = start + (n - 1) / len
16-
let reminder = (n - 1) % len
17-
return (''+target).charAt(reminder)
6+
let start = 1
7+
let len = 1
8+
let base = 9
9+
while(n > len * base) {
10+
n = n - len * base
11+
len++
12+
start *= 10
13+
base *= 10
14+
}
15+
let target = start + Math.floor((n - 1) / len)
16+
let reminder = (n - 1) % len
17+
return (''+target).charAt(reminder)
1818
};

0 commit comments

Comments
 (0)