MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / decode

Function decode

javascript/0091-decode-ways.js:67–75  ·  view source on GitHub ↗
(s, tabu)

Source from the content-addressed store, hash-verified

65};
66
67var decode = (s, tabu) => {
68 for (let curr = 2; curr < tabu.length; curr++) {
69 const [prev, prevPrev] = [curr - 1, curr - 2];
70 const isEqual = s[prev] === '0';
71 if (!isEqual) tabu[curr] += tabu[prev];
72
73 if (isTwoDigit(s, curr)) tabu[curr] += tabu[prevPrev];
74 }
75};
76
77var isTwoDigit = (s, index) => {
78 const twoDigit = Number(s.slice(index - 2, index));

Callers 1

numDecodingsFunction · 0.70

Calls 1

isTwoDigitFunction · 0.85

Tested by

no test coverage detected