We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 99357ba commit 7b274c7Copy full SHA for 7b274c7
Algorithm/src/offer/_44ANumberInADigitalSequence.java
@@ -0,0 +1,26 @@
1
+package offer;
2
+
3
+/**
4
+ * @author : CodeWater
5
+ * @create :2022-07-26-23:51
6
+ * @Function Description :44.数字序列中某一位的数字
7
+ */
8
+public class _44ANumberInADigitalSequence {
9
+ class Solution {
10
+ public int findNthDigit(int n) {
11
+ // n所在的位数
12
+ int digit = 1;
13
+ // start当前遍历的起始位置 count当前遍历相同位数的数字共有多少个
14
+ long start = 1 , count = 9 ;
15
+ while( n > count ){
16
+ n -= count;
17
+ digit += 1;
18
+ start *= 10;
19
+ count = digit * start * 9;
20
+ }
21
+ // 第n为数字出现在num中某一位上
22
+ long num = start + (n - 1) / digit;
23
+ return Long.toString(num).charAt( (n - 1) % digit ) - '0';
24
25
26
+}
0 commit comments