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

Method parseSimple

java/Chapter 17/Question17_14/Question.java:75–93  ·  view source on GitHub ↗
(int wordStart, int wordEnd)

Source from the content-addressed store, hash-verified

73 }
74
75 public static int parseSimple(int wordStart, int wordEnd) {
76 if (wordEnd >= sentence.length()) {
77 return wordEnd - wordStart;
78 }
79
80 String word = sentence.substring(wordStart, wordEnd + 1);
81
82 /* break current word */
83 int bestExact = parseSimple(wordEnd + 1, wordEnd + 1);
84 if (!dictionary.contains(word, true)) {
85 bestExact += word.length();
86 }
87
88 /* extend current word */
89 int bestExtend = parseSimple(wordStart, wordEnd + 1);
90
91 /* find best */
92 return Math.min(bestExact, bestExtend);
93 }
94
95 public static String clean(String str) {
96 char[] punctuation = {',', '"', '!', '.', '\'', '?', ','};

Callers

nothing calls this directly

Calls 3

lengthMethod · 0.45
containsMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected