408. Valid Word Abbreviation
注意 pay attention to the 0 before a digit!!!!
class Solution {
public:
bool validWordAbbreviation(string word, string abbr) {
int j = 0;
for(int i = 0; i < abbr.size(); i++, j++) {
int tmp = 0;
while (i < abbr.size() && isdigit(abbr[i])) {
if (tmp == 0 && abbr[i] == '0') return false;
tmp = tmp * 10 + abbr[i++] - '0';
}
j += tmp;
if (i == abbr.size()){
if (j == word.size()) return true;
return false;
}
if (j >= word.size() || word[j] != abbr[i]) return false;
}
return true;
}
};