---
# System prepended metadata

title: 0408. Valid Word Abbreviation
tags: [Leetcode, Easy]

---

# 0408. Valid Word Abbreviation
###### tags: `Leetcode` `Easy`
Link: https://leetcode.com/problems/valid-word-abbreviation/
## 注意
能不要在回圈里面套回圈提取数字就不要这么干
## Code
```java=
class Solution {
    public boolean validWordAbbreviation(String word, String abbr) {
        int skipLen = 0;
        int wordIdx = 0;
        for(int i = 0;i < abbr.length();i++){
            char letter = abbr.charAt(i);
            if(Character.isLetter(letter)){
            //     System.out.println(letter);
                wordIdx = wordIdx+skipLen;
                skipLen = 0;
                if(wordIdx >= word.length()){
                    return false;
                }
                if(word.charAt(wordIdx) != letter){
                    return false;
                }
                wordIdx++;
            }
            else if(Character.isDigit(letter)){
                int num = letter-'0';
                if(skipLen == 0 && num == 0) return false;
                skipLen = skipLen*10+num;
            }
        }
        return wordIdx+skipLen == word.length();
    }
}
```