1138. Digit Census
A numbering machine prints every integer of nums in plain decimal, and the quality team counts how often each digit is printed. Return an array of exactly 10 integers where entry d is the total number of times the digit d appears across the decimal representations of all numbers.
A minus sign is not a digit and is ignored, no leading zeros are printed, and the number 0 is printed as a single '0'. For example [10, -101] prints the digits 1,0,1,0,1, so entry 0 is 2 and entry 1 is 3. Peel digits off the absolute value with remainder and division by 10. Time is O(10n) with O(1) extra space.
Example 1
- Input:
- nums = [10,-101]
- Output:
- [2,3,0,0,0,0,0,0,0,0]
- Explanation:
The numbers write the digits 1,0 and 1,0,1 (the minus sign is ignored), so 0 appears twice and 1 appears three times.
Example 2
- Input:
- nums = [0,909]
- Output:
- [2,0,0,0,0,0,0,0,0,2]
- Explanation:
The value 0 contributes one '0', and 909 contributes 9, 0 and 9, so 0 appears twice and 9 appears twice.
Constraints
1 ≤ nums.length ≤ 104
-109 ≤ nums[i] ≤ 109
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(10n)
- Space
- O(1)