auto commit
This commit is contained in:
parent
58c76022e0
commit
268adf6568
|
@ -1410,17 +1410,15 @@ public int NumberOf1Between1AndN_Solution(int n) {
|
|||
|
||||
```java
|
||||
int digitAtIndex(int index) {
|
||||
if (index >= 0) {
|
||||
int digit = 1;
|
||||
while (true) {
|
||||
int amount = getAmountOfDigit(digit);
|
||||
int totalAmount = amount * digit;
|
||||
if (index < totalAmount) return digitAtIndex(index, digit);
|
||||
index -= totalAmount;
|
||||
digit++;
|
||||
}
|
||||
if (index < 0) return -1;
|
||||
int digit = 1;
|
||||
while (true) {
|
||||
int amount = getAmountOfDigit(digit);
|
||||
int totalAmount = amount * digit;
|
||||
if (index < totalAmount) return digitAtIndex(index, digit);
|
||||
index -= totalAmount;
|
||||
digit++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int getAmountOfDigit(int digit) {
|
||||
|
@ -1438,6 +1436,11 @@ private int beginNumber(int digits) {
|
|||
if (digits == 1) return 0;
|
||||
return (int) Math.pow(10, digits - 1);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Solution solution = new Solution();
|
||||
System.out.println(solution.digitAtIndex(1001));
|
||||
}
|
||||
```
|
||||
|
||||
## 45. 把数组排成最小的数
|
||||
|
|
Loading…
Reference in New Issue
Block a user