Practice/Meta/Leetcode 408. Valid Word Abbreviation
CodingMust
You are given a word and an abbreviation string. Your task is to determine whether the abbreviation is a valid representation of the word.
An abbreviation is formed by replacing sequences of characters in the original word with numbers that represent how many characters were replaced. For example, "internationalization" can be abbreviated as "i18n" (the letter 'i', followed by 18 characters, followed by 'n').
The abbreviation string may contain:
An abbreviation is valid if following its instructions (matching letters and skipping the specified number of characters) produces exactly the original word.
true if the abbreviation is valid, false otherwiseword consists of only lowercase English lettersabbr consists of lowercase English letters and digitsExample 1:
` Input: word = "internationalization", abbr = "i12iz4n" Output: true Explanation:
Example 2:
` Input: word = "apple", abbr = "a2e" Output: false Explanation:
Example 3:
Input: word = "substitution", abbr = "s010n" Output: false Explanation: Numbers with leading zeros are not allowed in valid abbreviations.
Example 4:
Input: word = "word", abbr = "4" Output: false Explanation: The abbreviation would skip 4 characters, but there are no letters to match. The entire word cannot be just a number without boundary letters.