Problem Statement |
| | A new library was founded in our city. The books were labeled 1, 2, 3, 4, etc., with no leading zeroes. A total of usedDigits digits were used to create the labels. Return the total number of books in the library, or -1 if usedDigits does not correspond to a valid solution.
|
| |
Definition |
| | | Class: | BooksNumbering | | Method: | numberOfBooks | | Parameters: | int | | Returns: | int | | Method signature: | int numberOfBooks(int usedDigits) | | (be sure your method is public) |
|
| |
|
| |
Constraints |
| - | usedDigits will be between 1 and 2 * 109, inclusive. |
| |
Examples |
| 0) | |
| | | Returns: 10 | | Each of the first 9 numbers (1-9) contain one digit. Number 10 contains 2 digits. Therefore, there's a total of 11 digits. |
|
|
| 1) | |
| | | Returns: -1 | | There is no possible solution. It takes 9 digits to label 9 books, and 11 digits to label 10 books. |
|
|
| 2) | |
| | |
| 3) | |
| | |
| 4) | |
| | |
| 5) | |
| | |
| 6) | |
| | |