Skip to content

Commit c28fb30

Browse files
committed
Updated word break 2
1 parent 2e36ed3 commit c28fb30

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

Hard/WordBreak2.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@
1515
public class Solution {
1616

1717
/**
18-
* memory function
19-
* store how a word can be decomposed
18+
* Memory function
19+
* Store how a word can be decomposed
2020
*/
2121
Map<String, List<String>> res = new HashMap<String, List<String>>();
2222

2323
/**
2424
* DP, Backtracking
25-
* Store previous backtracking result in a map
26-
* Generate every substring from front
27-
* If not a word, skip
28-
* If is a word, and if the length run out, add to current solution
25+
* Store successful decomposition in a map
26+
* Get prefix
27+
* If not in dictionary, just ignore
28+
* If in dictionary, check current position
29+
* If reaches the end, add prefix to a solution
2930
* If within length do the following:
30-
* check whether the rest of the string is already broken
31+
* Check whether the rest of the string is already decomposed
3132
* If not, backtracking the rest of the string
3233
* If yes, get the result from memory function
3334
* If there is an result, add each word to current solution with front in

0 commit comments

Comments
 (0)