class Solution(object):
def findNthDigit(self, n):
"""
:type n: int
:rtype: int
"""
# https://leetcode.com/problems/nth-digit/discuss/88363/Java-solution
count = 9
start = 1
curr_len = 1
while n > curr_len * count:
n -= curr_len * count
curr_len += 1
count *= 10
start *= 10
start += (n - 1) / curr_len
s = str(start)
return int(s[(n - 1) % curr_len]
Download Nth Digit.pyLeetcode 400 Nth Digit problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.