Given s = "internationalization", abbr = "i12iz4n":
Return true.
Given s = "apple", abbr = "a2e":
Return false.
public class Solution {
public boolean validWordAbbreviation(String word, String abbr) {
int len = 0;
int i = 0, j = 0;
while(i < word.length() && j < abbr.length()){
if(word.charAt(i) == abbr.charAt(j)){
i++;
j++;
continue;
}
if(abbr.charAt(j) <= '0' || abbr.charAt(j) > '9'){
return false;
}
int start = j;
while(j< abbr.length() && abbr.charAt(j) >= '0' && abbr.charAt(j) <= '9'){
j++;
}
int num = Integer.valueOf(abbr.substring(start, j));
i += num;
}
return i == word.length() && j == abbr.length();
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。