bool isStringNumeric(const string& str) {
for (char c : str) {
if (!isdigit(c)) {
return false;
}
}
return true;
}
class Solution {
public:
vector<int> lastVisitedIntegers(vector<string>& words) {
vector<int> inte;
vector<int> ans;
int k=1;
for(int i=0;i<words.size();i++)
{
if(isStringNumeric(words[i]))
inte.push_back(stoi(words[i]));
else
{
if(i!=0 && !isStringNumeric(words[i-1]))
{
k++;
}
else
k=1;
reverse(inte.begin(),inte.end());
if(k>inte.size())
ans.push_back(-1);
else
ans.push_back(inte[k-1]);
reverse(inte.begin(),inte.end());
}
}
return ans;
}
};