Basically, just iterate through all the numbers in nums,
convert them to string and check the length of the string and see if it is divisible by 2.
code
class Solution {
public:
int findNumbers(vector<int>& nums) {
int ans = 0;
for (int num : nums) {
string temp = to_string(num);
if (temp.size() % 2 == 0) {
++ans;
}
}
return ans;
}
};
complexity
- Time:
O(n)- Space:
O(1)
time taken
- 1 minutes and 8 seconds