Menu
CoddyTech

Count Digits

Write a function that gets a non-negative integer n and returns how many digits it has when you write it in base 10 without leading zeros. Zero is written as a single 0, so it has one digit.

Function

countDigits(n: integer) → integer
ninteger
the non-negative integer to measure
Returnsinteger
the number of decimal digits in n

Constraints

  • 0 ≤ n ≤ 231-1

Examples

Input
n = 4096
Output
4
Explanation
Integer division by 10 takes 4096 to 409, 40 and 4. That is three digits removed and one left, so the answer is 4.

lock icon+16 hidden tests on Submit

challenge icon

Follow-up

Can you count the digits without a loop that runs once per digit, for example with a binary search over the powers of ten?

Reset code
def countDigits(n):
    # Write code here
Test cases

Case 1

Case 2

Case 3

Input

n = 4096

Expected

4