1295. Statistics with even digits (C++)
1 topic description
You are an integer array nums, please return the number of digits with even digits.
2 Example description
2.1 Example 1
Input: nums = [12,345,2,6,7896]
Output: 2
Explanation:
12 is a 2-digit number (the digits are even)
345 is a 3-digit number (the digits are odd)
2 is a 1-digit number (the digits are odd )
6 is a 1-digit number with an odd number of digits)
7896 is a 4-digit number (the number of digits is even)
so only 12 and 7896 are even-numbered numbers
2.2 Example 2
Input: nums = [555,901,482,1771]
Output: 1
Explanation:
Only 1771 is a number with even digits.
3 Problem solving tips
1 <= nums.length <= 500
1 <= nums[i] <= 10^5
4 Detailed source code (C++)
class Solution {
public:
int findNumbers(vector<int>& nums) {
int count = 0;
for (int i = 0 ; i < nums.size() ; i ++)
{
if(to_string(nums[i]).size() % 2 == 0)
{
count ++ ;
}
}
return count;
}
};