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

Function dfs

javascript/0139-word-break.js:23–35  ·  view source on GitHub ↗
(s, wordSet, start)

Source from the content-addressed store, hash-verified

21};
22
23var dfs = (s, wordSet, start) => {
24 for (let end = start + 1; end <= s.length; end++) {
25 /* Time O(N) */
26 const word = s.slice(start, end); /* Time O(N) | Space O(N) */
27
28 const _canBreak =
29 wordSet.has(word) &&
30 canBreak(s, wordSet, end); /* Time O(2^N) | Space O(N) */
31 if (_canBreak) return true;
32 }
33
34 return false;
35};
36
37/**
38 * DP - Top Down

Callers 1

canBreakFunction · 0.70

Calls 1

canBreakFunction · 0.85

Tested by

no test coverage detected