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

Function delimitWord

javascript/0271-encode-and-decode-strings.js:40–53  ·  view source on GitHub ↗
(str, index)

Source from the content-addressed store, hash-verified

38};
39
40const delimitWord = (str, index) => {
41 const delimiter = str.indexOf('#', index); /* Time O(K) */
42 const length = Number(str.slice(index, delimiter)); /* Time O(K) */
43 const [start, end] = [delimiter + 1, delimiter + length + 1];
44 const word = str.slice(
45 start,
46 end,
47 ); /* Time O(K) | Ignore Auxillary Space O(K) */
48
49 return {
50 nextIndex: end,
51 word,
52 };
53};
54
55/**
56 * Non-ASCII Delimiter - Ignore Auxiliary Space

Callers 1

decodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected