-
Notifications
You must be signed in to change notification settings - Fork 0
/
ntg_digit.py
66 lines (61 loc) · 1.56 KB
/
ntg_digit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# class Solution:
#
# def get_d(self, n):
# a = 0
# nin = mulfact = 9
# i = 2
# d = 0
# mulpli = 10
# while (True):
# if n <= mulfact:
# return a, d
# else:
# d = (d * 10) + 10
# a = mulfact
# mulfact = nin * i * mulpli
# mulpli *= 10
# i += 1
#
# def findNthDigit(self, n: int) -> int:
# if n < 10:
# return n
# num = 10
# n = n - 10
# d, num = self.get_d(n)
# print(n, d, num)
# while (True):
# c = num
# arr = []
# while (True):
# mod = int(c % 10)
# arr.append(mod)
# c = int(c / 10)
# d += 1
# if c == 0:
# break
# if n <= d:
# d -= len(arr) - 1
# for i in range(len(arr)):
# if n == d:
# return arr.pop()
# arr.pop()
# d += 1
# num += 1
class Solution(object):
def findNthDigit(self, n):
"""
:type n: int
:rtype: int
"""
if n <= 9: return n
i, p = 1, 9
while True:
n += p
p = p * 10 + 9
i += 1
if n < p * i:
x = (n + i - 1)
y = int(x // i)
z = x % i
return int(str(z))
print(Solution().findNthDigit(11))