题解 | #数字序列中某一位的数字#
数字序列中某一位的数字
http://www.nowcoder.com/practice/29311ff7404d44e0b07077f4201418f5
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param n int整型
* @return int整型
*/
public int findNthDigit (int n) {
// write code here
if(n < 10){
return n;
}
n--;
int num = 0;
int k = 1;
while(n > 0){
num = n;
n = (int)(n - Math.pow(10,k-1)*9*k);
k++;
}
int a = num/(k-1);
int b = num%(k-1);
a = a + (int)Math.pow(10,k-2);
String s = a+"";
System.out.print(b);
return Integer.parseInt(s.substring(b,b+1));
}
}

查看24道真题和解析