408. Valid Word Abbreviation

202408291735
tags: #two-pointers

var validWordAbbreviation = function(word, abbr) {
	let number = 0;
	let i = 0, j = 0;
	while (i < word.length && j < abbr.length) {
		if (!isNaN(abbr[j])) {
			number = number * 10 + Number(abbr[j])
			if (number === 0) {
				return false;
			}
			j += 1;
		} else {
			i += number;
			if (i >= word.length || word[i] !== abbr[j]) {
				return false;
			}
			number = 0;
			i += 1;
			j += 1;
		}
	}
	i += number;
	return i === word.length && j === abbr.length;
};

Reference

https://leetcode.com/problems/valid-word-abbreviation