# 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(); } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up