File: find-numbers-with-even-number-of-digits/solution.py

Date: 2026-06-06

Time: 16:40

find-numbers-with-even-number-of-digits/solution.py

Purpose

This file is a self-contained solution to LeetCode 1295: Find Numbers with Even Number of Digits. It owns both the algorithm implementation and its test suite, following the repo-wide convention of colocating solution and tests in a single file per problem.

Key Components

Solution.findNumbers(nums: List[int]) -> int — The core method. Takes a list of positive integers and returns how many of them have an even digit count. The implementation is a single generator expression:


return sum(1 for n in nums if len(str(n)) % 2 == 0)

It converts each number to its string representation, checks if the length is even, and sums the truthy results.

TestFindNumbers — A unittest.TestCase with 7 test methods covering:

Patterns

Dependencies

Imports: typing.List (type annotation) and unittest (test framework). No project-internal dependencies.

Imported by: The massive importedby list is misleading — those are other problems' test files, likely sharing a common test runner or import pattern, not actually importing findNumbers. The real consumer is find-numbers-with-even-number-of-digits/testsolution.py, which presumably imports the Solution class.

Flow

1. Instantiate Solution

2. Call findNumbers([12, 345, 2, 6, 7896])

3. Generator iterates: 12"12" → len 2 → even → count 1; 345 → len 3 → odd → skip; 2 → len 1 → skip; 6 → len 1 → skip; 7896 → len 4 → even → count 1

4. sum returns 2

Invariants

Error Handling

None. The method trusts its caller to provide valid input, consistent with LeetCode solution conventions. No try/except, no input validation. If nums is None, it raises TypeError from the generator; if an element is non-numeric, str() still works but len() would count non-digit characters.

Topics to Explore

Beliefs