数学题
Go版本:
import (
"strconv"
)
func findNthDigit(n int) int {
// 0-9 1 9个
// 10-99 二 90
// 100-999 3 900
// 数学找规律的题目
if(n<10){
return n;
}
//
border,start,loc:=9,1,1;
for n>border{
n-=border;
start++;
loc=loc*10;
border=start*9*loc;
}
num:=loc+(n-1)/start;
num_str:=strconv.Itoa(num)
index := (n-1)%start
return int(num_str[index]-'0');
}
网友评论