It is a question of leetcode : https://leetcode.com/explore/learn/card/fun-with-arrays/521/introduction/3237/
Given an array nums of integers, return how many of them contain an even number of digits. When I am attempting it without using iterators all test cases are passed, while using the iterator approach as shown below it is showing Buffer Overflow Error, although any custom test case is getting passed.
Can you tell why this iterator approach is failing, why this overflow error is occurring and how to rectify it ?

class Solution {
int calculate_digit(int n){
int count = 0;
while(n){
n = int(n/10);
count++;
}
return count;
}
public:
int findNumbers(vector<int>& nums) {
int check;
vector<int>::iterator it;
for (auto it = nums.begin(); it != nums.end(); ++it){
check = calculate_digit(*it);
if(check%2 != 0)
nums.erase(it);
}
return nums.size()-1;
}
};