# Leetcode 400 - Nth digit

Note:

• Based on this partterns, use a while loop to find the length of target number. Keep subtracting from n.
• After the while loop, use offset = Math.ceil(n / digits) - 1 to find what the target number is.
• For example, the input was 11, and now n === 2. So the target number is 10.
• How to find the index?
• If n % digits === 0, it’s the last digit.
• If not, it’s n % digits - 1.
• Convert the number string and return num[index].

Question:

Given an integer n, return the nth digit of the infinite integer sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …].

Example:

Code: