MCPcopy
hub / github.com/careercup/ctci / canBuildWord

Method canBuildWord

java/Chapter 18/Question18_7/Question.java:22–36  ·  view source on GitHub ↗
(String str, boolean isOriginalWord, HashMap<String, Boolean> map)

Source from the content-addressed store, hash-verified

20 }
21
22 public static boolean canBuildWord(String str, boolean isOriginalWord, HashMap<String, Boolean> map) {
23 if (map.containsKey(str) && !isOriginalWord) {
24 return map.get(str);
25 }
26 for (int i = 1; i < str.length(); i++) {
27 String left = str.substring(0, i);
28 String right = str.substring(i);
29 if (map.containsKey(left) && map.get(left) == true &&
30 canBuildWord(right, false, map)) {
31 return true;
32 }
33 }
34 map.put(str, false);
35 return false;
36 }
37
38 public static void main(String[] args) {
39 String[] arr = createGiantArray();

Callers 1

printLongestWordMethod · 0.95

Calls 3

putMethod · 0.80
getMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected