Given a non-empty string s and an abbreviation abbr, return whether the string matches with the given abbreviation.
A string such as “word” contains only the following valid abbreviations:
Notice that only the above abbreviations are valid abbreviations of the string “word”. Any other string is not a valid abbreviation of “word”.
Note:
Assume s contains only lowercase letters and abbr contains only lowercase letters and digits.
Example 1:
Example 2:
解法1:
string类的题目似乎用指针可以规避掉一些cornercase的处理。这题用两个指针维护当前比较的起始位置。
先比较是否相等,如果相等则都往前进一步。
如果不相等,则考虑abbr是否为数字,把数字parse出来后i相应的比较位置就前进对应的数字个数。
这里要注意的是,数字的开端不能为0.
C++
Java