From 268adf656864600374c91a3fdc90e267b2537f8c Mon Sep 17 00:00:00 2001 From: CyC2018 <1029579233@qq.com> Date: Thu, 1 Mar 2018 11:03:55 +0800 Subject: [PATCH] auto commit --- notes/剑指 offer 题解.md | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/notes/剑指 offer 题解.md b/notes/剑指 offer 题解.md index 3fe9200a..22ad72b3 100644 --- a/notes/剑指 offer 题解.md +++ b/notes/剑指 offer 题解.md @@ -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. 把数组排成最小的数