Given a non-negative integer n, return how many digits it has.
The digits are the figures from 0 to 9 that n is written with. Dividing a number by 10 without the remainder removes its last digit (542 becomes 54), so you can count how many times that happens until the number is 0. The number 0 itself has one digit.
Example 1:
Input: n = 542 Output: 3 Explanation: 542 is written with three digits: 5, 4 and 2.
Example 2:
Input: n = 100 Output: 3 Explanation: The zeros are digits too: 1, 0 and 0.
Example 3:
Input: n = 0 Output: 1 Explanation: 0 is written with one digit.
Constraints:
0 <= n <= 109
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
