题解 |
数字序列中某一位的数字
http://www.nowcoder.com/practice/29311ff7404d44e0b07077f4201418f5
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param n int整型
# @return int整型
#
class Solution:
def findNthDigit(self , n: int) -> int:
# write code here
zhishu=1
c=0
while True:
if n<=9*(10**(zhishu-1))*zhishu:
if n%zhishu==0:
index1=n/zhishu
index2=zhishu-1
else:
index1=n//zhishu+1
index2=n%zhishu-1
s=int(str(c+index1)[index2])
return s
else:
n=n-9*(10**(zhishu-1))*zhishu
c+=9*(10**(zhishu-1))
zhishu+=1
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param n int整型
# @return int整型
#
class Solution:
def findNthDigit(self , n: int) -> int:
# write code here
zhishu=1
c=0
while True:
if n<=9*(10**(zhishu-1))*zhishu:
if n%zhishu==0:
index1=n/zhishu
index2=zhishu-1
else:
index1=n//zhishu+1
index2=n%zhishu-1
s=int(str(c+index1)[index2])
return s
else:
n=n-9*(10**(zhishu-1))*zhishu
c+=9*(10**(zhishu-1))
zhishu+=1