MCPcopy Index your code
hub / github.com/doocs/leetcode / dfs

Method dfs

solution/0200-0299/0291.Word Pattern II/Solution.java:19–45  ·  view source on GitHub ↗
(int i, int j)

Source from the content-addressed store, hash-verified

17 }
18
19 private boolean dfs(int i, int j) {
20 if (i == m && j == n) {
21 return true;
22 }
23 if (i == m || j == n || m - i > n - j) {
24 return false;
25 }
26 char c = p.charAt(i);
27 for (int k = j + 1; k <= n; ++k) {
28 String t = s.substring(j, k);
29 if (d.getOrDefault(c, "").equals(t)) {
30 if (dfs(i + 1, k)) {
31 return true;
32 }
33 }
34 if (!d.containsKey(c) && !vis.contains(t)) {
35 d.put(c, t);
36 vis.add(t);
37 if (dfs(i + 1, k)) {
38 return true;
39 }
40 vis.remove(t);
41 d.remove(c);
42 }
43 }
44 return false;
45 }
46}

Callers 1

wordPatternMatchMethod · 0.95

Calls 5

equalsMethod · 0.45
containsMethod · 0.45
putMethod · 0.45
addMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected