Date: 2026-06-06
Time: 16:40
find-numbers-with-even-number-of-digits/solution.pyThis 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.
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:
100000 (6 digits, even)str(n) rather than math.log10 or repeated division. This is the idiomatic Python approach — simpler, correct for all positive integers, and avoids floating-point edge cases that log10 introduces.sum: The sum(1 for ...) pattern counts matches without building an intermediate list. Equivalent to len([...]) but more memory-efficient.if _name == "main_" guard allows running tests directly via python solution.py.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.
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
1 <= nums[i] <= 10^5). Negative numbers would include the - sign in str(n), inflating the digit count by 1 — the code does not guard against this.str(0) returns "0" (length 1, odd), which is correct but 0 is outside the stated constraint range.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.
find-numbers-with-even-number-of-digits/test_solution.py — The separate test file that imports this solution; clarifies the actual import relationshipfind-numbers-with-even-number-of-digits/review.md — Code review notes that may document alternative approaches (log10, division loop)str-vs-log10-digit-counting — Why len(str(n)) is preferred over math.log10 in Python despite being O(d) in digit count — floating-point precision issues with log10(1000) returning 2.9999...count-integers-with-even-digit-sum/solution.py — Related digit-manipulation problem; compare how digit extraction is handled when you need digit values, not just countruntests.py — The repo-wide test runner; explains why so many test files appear in the importedby liststr-digit-count-correctness — findNumbers is correct for all positive integers in [1, 10^5] but would miscount negative integers due to the - character in str(n)single-pass-no-allocation — The generator expression processes the list in a single pass with O(1) auxiliary memory (no intermediate list constructed)solution-test-colocation — Every problem directory contains a solution.py with both the Solution class and a unittest.TestCase subclass, runnable standalone via _main_no-input-validation — The solution performs zero input validation, relying on LeetCode's constraint guarantees (1 <= nums[i] <= 10^5, 1 <= nums.length <= 500)