You are viewing a single comment's thread. Return to all comments →
js recursive
function abbreviation(a, b, i = a.length - 1, j = b.length - 1, dp = {}) { if (j < 0) return 'YES'; if (i < 0) return 'NO'; const k = `${i}-${j}`; if (!dp[k]) { const c1 = a[i]; const c2 = b[j]; const isCap = c1 < 'a'; dp[k] = c1.toUpperCase() === c2 && abbreviation(a, b, i - 1, j - 1, dp) === 'YES' || !isCap && abbreviation(a, b, i - 1, j, dp) === 'YES' ? 'YES' : 'NO'; } return dp[k]; }
Seems like cookies are disabled on this browser, please enable them to open this website
Abbreviation
You are viewing a single comment's thread. Return to all comments →
js recursive