Find Numbers with Even Number of Digits

easy array math

Problem

You are given an array nums of positive integers (up to 500 values, each between 1 and 10⁵). Return how many of them are written with an even number of digits. For example, 12 has two digits (even), while 345 has three (odd).

Inputnums = [12, 345, 2, 6, 7896]
Output2
12 has 2 digits and 7896 has 4 digits — both even — while 345, 2, and 6 have odd digit counts.

def find_numbers(nums):
    count = 0
    for x in nums:
        digits = 0
        while x > 0:
            x //= 10
            digits += 1
        if digits % 2 == 0:
            count += 1
    return count
function findNumbers(nums) {
  let count = 0;
  for (let x of nums) {
    let digits = 0;
    while (x > 0) {
      x = Math.floor(x / 10);
      digits++;
    }
    if (digits % 2 === 0) count++;
  }
  return count;
}
int findNumbers(int[] nums) {
    int count = 0;
    for (int x : nums) {
        int digits = 0;
        while (x > 0) {
            x /= 10;
            digits++;
        }
        if (digits % 2 == 0) count++;
    }
    return count;
}
int findNumbers(vector<int>& nums) {
    int count = 0;
    for (int x : nums) {
        int digits = 0;
        while (x > 0) {
            x /= 10;
            digits++;
        }
        if (digits % 2 == 0) count++;
    }
    return count;
}
Time: O(n · d) Space: O(1)