class Solution {
public:
int getCnt(int cand) {
int count = 0;
while(cand) {
cand /= 10;
count++;
}
return count;
}
int findNumbers(vector<int>& nums) {
const int size = nums.size();
int sol = 0;
for(int i=0; i<size; i++) {
int cand = getCnt(nums[i]);
if(cand % 2 == 0) {
sol++;
}
}
return sol;
}
};
흠 또무엇인지 속도에 문제가 있나보다.
Runtime: 8 ms, faster than 74.81% of C++ online submissions for Find Numbers with Even Number of Digits. Memory Usage: 8.9 MB, less than 100.00% of C++ online submissions for Find Numbers with Even Number of Digits.
같은 소스를 다시 한번 제출해 보았다.
Runtime: 4 ms, faster than98.44%ofC++online submissions forFind Numbers with Even Number of Digits.
Memory Usage: 9 MB, less than100.00%ofC++online submissions forFind Numbers with Even Number of Digits.