Explanation

478.Count the Number of Digits in an Integer

Easy
Given a non-negative integer n, return how many digits it has. The loopDivision LoopRepeatedly dividing by 10, counting divisions until the value reaches 0 — each division strips off exactly one digit. version is the classic numeric approach: it works the same way in every language and makes the "one digit per division" relationship explicit. The string conversionString ConversionConverting the number to its textual form and reading off its character count — the digit count falls out for free. version sidesteps the arithmetic entirely by treating digit-counting as a text problem instead.

Example 1:

Input: n = 1234

Output: 4

Example 2:

Input: n = 0

Output: 1

Example 3:

Input: n = 7

Output: 1

+ 4 hidden test cases run on Submit.

Constraints:

  • ●0 ≤ n ≤ 1000000000

n =

1234