Valid Word Abbreviation
A string can be abbreviated by replacing any number of non-adjacent, non-empty substrings with their lengths (the replaced substrings must not be adjacent). Given a full word and an abbreviation abbr, return true if abbr is a valid abbreviation of word. Numbers in abbr must not contain leading zeros.
Open official problem prompt ↗Verify that an abbreviation, where numbers stand for counts of skipped letters, exactly reconstructs the given word.
Following shorthand directions where a number means 'walk past that many houses': you and the map must arrive at the same address, and a note like '05' (a leading zero) is nonsense and disqualifies the route.
- Input
- word = "internationalization", abbr = "i12iz4n"
- Output
- true
- Why
- i + (skip 12) + iz + (skip 4) + n reconstructs 'i' + 'nternationaliz'... exactly matching all 20 letters of the word.
1 <= word.length <= 20word consists of only lowercase English letters1 <= abbr.length <= 10abbr consists of lowercase English letters and digits