408. Valid Word Abbreviation

Given anon-emptystringsand an abbreviationabbr, return whether the string matches with the given abbreviation.
A string such as"word"contains only the following valid abbreviations:
["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"]
Notice that only the above abbreviations are valid abbreviations of the string"word". Any other string is not a valid abbreviation of"word".
Note:Assumescontains only lowercase letters andabbrcontains only lowercase letters and
digits.
Example 1: Givens= "internationalization",abbr= "i12iz4n":Return true.

这么一道简单的小题, 抠嗤了一个多小时, 

两点老生常谈的问题:
1: 命名规则要好好些, 不要用i,j 乱指一通, 很容易颠倒。
2: 考虑问题, 先正向思维, 这样逻辑不容易出错。发现正向有弊端,再考虑逆向。


408. Valid Word Abbreviation_第1张图片

你可能感兴趣的:(408. Valid Word Abbreviation)