Count how many integers in an array have an even number of decimal digits.
Given an integer array nums, determine how many elements contain an even number of digits in base 10.
You only need to inspect each number independently and count its digits. Negative numbers are not part of the standard problem form; treat the input as non-negative integers.
Input Format
- An integer array
nums. - Each element of
numsis a non-negative integer.
Output Format
Return the number of values in nums whose decimal representation has an even length.
Constraints
1 <= nums.lengthis assumed in the standard problem.- Values are non-negative integers.
- A direct per-element scan is sufficient.
Example 1
Input
nums = [12, 345, 2, 6, 7896]
Output
2
Explanation
12 has 2 digits and 7896 has 4 digits, so there are 2 numbers with an even number of digits.
Example 2
Input
nums = [555, 901, 482, 1771]
Output
1
Explanation
Only 1771 has an even number of digits.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.