Skip to main content
impol.dev

Editorial

Solution walkthrough

Review the explanation, then compare the reference implementation.

Video explanation

Solution

Intuition

The inputs are positive integers, so the length of their ordinary decimal string is exactly their digit count. Only that count's parity matters, not the digits themselves.

Approach

Convert each number to its decimal representation. If the representation's length is divisible by two, increment the answer; otherwise leave the count unchanged. Return the total after processing the array. Each occurrence is checked separately, so repeated qualifying values contribute separately. String conversion also handles powers of ten exactly without floating-point logarithms.

class Solution: def findNumbers(self, nums: List[int]) -> int: n = len(nums) res = 0 for x in nums: if len(str(x)) % 2 == 0: res += 1 return res

Complexity analysis

Let n be the number count and D the total digits across all values. Converting each value to text takes O(D) time overall and O(d_max) transient auxiliary space for the longest converted number.