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

Function dfs

javascript/0472-concatenated-words.js:22–35  ·  view source on GitHub ↗

* * @param {string} word * @returns {boolean}

(word)

Source from the content-addressed store, hash-verified

20 * @returns {boolean}
21 */
22 function dfs(word) {
23 for (let i = 1; i < word.length; i++) {
24 let prefix = word.slice(0, i);
25 let suffix = word.slice(i, word.length);
26
27 if (
28 (wordSet.has(prefix) && wordSet.has(suffix)) ||
29 (wordSet.has(prefix) && dfs(suffix))
30 ) {
31 return true;
32 }
33 }
34 return false;
35 }
36};

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected