710. Count Digits in a Number

EasyRecursionRecursion

Given an integer n, return the number of digits in its decimal representation. Treat negative numbers as if the minus sign were not there (e.g., -123 has 3 digits). The number 0 has exactly 1 digit. You must compute this recursively without loops.

Input: A single integer n.

Output: Return an integer representing the digit count.

Examples

Example 1
Input: 12345
Output: 5
Explanation: Five digits: 1,2,3,4,5.
Example 2
Input: 0
Output: 1
Explanation: Zero is a single digit.
Example 3
Input: -987
Output: 3
Explanation: Sign is ignored; 987 has 3 digits.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →