Easy
Count Digits in an Integer
- Time limit
- 1 s
- Memory limit
- 128 MB
- Estimated
- 10 min
- Programming Fundamentals
Description
Given a non-negative integer n, return the total number of decimal digits in its standard representation.
A digit is any character from 0 to 9. Leading zeroes are not considered part of an integer's standard representation.
For example, the number 5832 contains four digits. The number 700 contains three digits. The number 0 is considered to contain exactly one digit.
Implement the function countDigits(n) that returns the number of digits in n.
Constraints
0 <= n <= 9007199254740991
Sample cases
3Sample 1
Input
n = 5832
Expected output
4
Sample 2
Input
n = 7
Expected output
1
Sample 3
Skills and languages
Concepts
- Number Bases and Digit Manipulation
Languages
- Python 3
Solve this problem
Create a free account to write, run and submit your solution.
- Write Python or Java in the browser, with your draft saved as you type
- Run your code on the examples as often as you like
- Submit to a sandboxed judge and see exactly which case failed
- Ask the AI mentor for a hint without being handed the answer