Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def validWordAbbreviation(self, word: str, abbr: str) -> bool:
- first = 0
- second = 0
- while (first < len(word) and second < len(abbr)):
- if word[first] == abbr[second]:
- first += 1
- second += 1
- elif (abbr[second] == '0'):
- return False
- elif abbr[second].isnumeric():
- count = 0
- while (second<len(abbr) and abbr[second].isnumeric()):
- count = count*10 + int(abbr[second])
- second += 1
- first = first + count
- else:
- return False # what if characters don't match; what if the
- return first == len(word) and second == len(abbr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement