4022. K-th Digit in Infinite String
You are given an integer
k.An infinite string is formed by concatenating the decimal representations of the positive integers, without separators.
For every nonnegative integer
b, blockbcontains the positive integers from10 * bthrough10 * b + 9. The integers in each block are appended as follows:
- If
bis even, append the integers in increasing order.- If
bis odd, append the integers in decreasing order.Therefore, the string starts with the integers 1 through 9, followed by 19 through 10, then 20 through 29, then 39 through 30, and so on.
Return the
k^thdigit (1-indexed) of this string.
1 | class Solution { |