Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created April 30, 2025 21:14
Show Gist options
  • Save Ifihan/25592ea899e7d8767f6a3e64e50d3d89 to your computer and use it in GitHub Desktop.
Save Ifihan/25592ea899e7d8767f6a3e64e50d3d89 to your computer and use it in GitHub Desktop.
Find Numbers with Even Number of Digits

Question

Approach

To solve this, I just iterated through the nums array and for each number, I counted the number of digits using either len(str(num)) or logarithmic math. If the number of digits was even, I incremented a counter.

Implementation

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

Complexities

  • Time: O(n)
  • Space: O(1)
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment