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

Function decode

javascript/0271-encode-and-decode-strings.js:23–38  ·  view source on GitHub ↗
(str, index = 0, decodedWords = [])

Source from the content-addressed store, hash-verified

21 * @return {string[]}
22 */
23var decode = (str, index = 0, decodedWords = []) => {
24 while (index < str.length) {
25 /* Time O(N) */
26 const { nextIndex, word } = delimitWord(
27 str,
28 index,
29 ); /* Time O(K) | Ignore Auxillary Space Space (K) */
30
31 decodedWords.push(
32 word,
33 ); /* | Ignore Auxillary Space O(N * K ) */
34 index = nextIndex;
35 }
36
37 return decodedWords;
38};
39
40const delimitWord = (str, index) => {
41 const delimiter = str.indexOf('#', index); /* Time O(K) */

Callers

nothing calls this directly

Calls 2

delimitWordFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected