Skip to content

Commit ccc4a2e

Browse files
author
chenxuyan
committed
格式化代码
1 parent 0fea67e commit ccc4a2e

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

solution/0400-0499/0400.Nth Digit/Solution.java

+10-12
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ public int findNthDigit(int n) {
66
* 举例15,15-9=6,6/2=3...0,余数是0,那么这个数值value=10*(2-1)+(3-1)=12,整除取最后一位 12%10=2
77
* 举例14,14-9=5,5/2=2...1,余数不为0,那么这个数值value=10*(2-1)+2=12,则为这个数的第余数个 12/(10*(2-1))%10=1
88
*/
9-
long max=9;
10-
long num=n;
11-
long digits=1;
12-
while (n>0) {
13-
if(num-max*digits>0) {
14-
num=num-max*digits;
9+
long max = 9;
10+
long num = n;
11+
long digits = 1;
12+
while (n > 0) {
13+
if (num - max * digits > 0) {
14+
num = num - max * digits;
1515
digits++;
16-
max=max*10;
17-
}else {
18-
long count=num/digits;
19-
long childDigits=num%digits;
20-
long value=(long)Math.pow(10,digits-1)+count-1;
16+
max = max * 10;
17+
} else {
18+
long count = num / digits;
19+
long childDigits = num % digits;
2120
if (childDigits == 0) {
2221
return (int) (((long) Math.pow(10, digits - 1) + count - 1) % 10);
2322
} else {
@@ -26,6 +25,5 @@ public int findNthDigit(int n) {
2625
}
2726
}
2827
return 0;
29-
3028
}
3129
}

0 commit comments

Comments
 (0)