Count Digits

Easy~10 min

Given an integer n, return the number of digits in n.

  • Negative numbers should be treated the same as their positive counterpart (ignore the sign).
  • The number 0 has 1 digit.

For example, 12345 has 5 digits, -42 has 2 digits, and 0 has 1 digit.

Examples

Example 1
Input: n = 12345
Output: 5
Explanation: The digits are 1, 2, 3, 4, 5.
Example 2
Input: n = -42
Output: 2
Explanation: Ignoring the sign, the digits are 4 and 2.
Example 3
Input: n = 0
Output: 1
Explanation: Zero is a single digit.

Constraints

  • -10^9 <= n <= 10^9
Code
Ctrl+EnterRun|Ctrl+⇧+EnterSubmit
Output

Run your code to see results

Use Cmd+Enter to run