题目描述
Given a number n, count the total number of digits required to write all numbers from 1 to n.
Example 1:
Input: n = 13
Output: 17
Explanation: There are total 17
digits required to write all
numbers from 1 to 13.
Example 2:
Input: n = 4
Output: 4
Explanation: There are total 4
digits required to write all
numbers from 1 to 4.
Your Task:
You dont need to read input or print anything. Complete the function totalDigits() which takes n as input parameter and returns the total number of digits required to write all numbers from 1 to n.
Expected Time Complexity: O(logn)
Expected Auxiliary Space: O(1)
Constraints:
1<= n <=100000
输入格式
见题面
输出格式
见题面
样例输入
n = 13
样例输出
17