public class Solution {
public boolean validWordAbbreviation(String word, String abbr) {
if (word == null || abbr == null) return false;
int i = 0;
int temp = 0;
int len = word.length();
for (char c : abbr.toCharArray()) {
if (c >= '0' && c <= '9') {
if (temp == 0 && c == '0') return false;
temp = temp * 10 + c - '0';
continue;
}
if (temp > 0) {
i+= temp;
temp = 0;
}
if ( i >= len || word.charAt(i++) != c) return false;
}
i += temp > 0 ? temp : 0;
return i == word.length();
}
}
public class Solution {
public boolean validWordAbbreviation(String word, String abbr) {
if(word==null || word.length()==0 || abbr ==null || abbr.length()==0)return false;
int i=0,j=0,m=word.length(),n=abbr.length();
while(i<m && j<n){
if(abbr.charAt(j)>='0' && abbr.charAt(j)<='9'){
if(abbr.charAt(j)=='0')return false;
int val=0;
while(j<n && abbr.charAt(j)>='0' && abbr.charAt(j)<='9'){
val=val*10+abbr.charAt(j++)-'0';
}
i+=val;
}else{
if(word.charAt(i++) !=abbr.charAt(j++)) return false;
}
}
return i==m && j==n;
}
}