给你一个整数 n ,请你在无限的整数序列 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …] 中找出并返回第 n 位上的数字。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/nth-digit
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
public static void main(String[] args) {
System.out.println(findNthDigit(11));
}
public static int findNthDigit(int n) {
String str = "";
for (int i = 1; i <=n ; i++) {
str = str+i;
}
char ch=str.charAt(n-1);
int num = ch-'0';
return num;
}
超出时间限制 明天继续看 最近在实习