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.
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
- Time: O(n)
- Space: O(1)
