- public class Solution {
- public boolean validWordAbbreviation(String word, String abbr) {
- intindex1 = 0;
- intindex2 = 0;
- char[] a = word.toCharArray();
- char[] b = abbr.toCharArray();
- while(index1 < a.length && index2 < b.length) {
- if(a[index1] != b[index2]) {
- intnum = 0;
- if(index2 < b.length && b[index2] - '0' <= 0 || b[index2] - '0' > 9) {
- return false;
- }
- while(index2 < b.length && b[index2] - '0' >= 0 && b[index2] - '0' <= 9) {
- num = num * 10 + b[index2] - '0';
- index2++;
- }
- if(num == 0) {
- return false;
- } else {
- intcount = 0;
- while(count < num) {
- if(count < num && index1 > a.length - 1) {
- return false;
- }
- index1++;
- count++;
- }
- }
- } else {
- index1++;
- index2++;
- }
- }
- returnindex1 == a.length && index2 == b.length;
- }
- }
来源: