Skip to content

Commit b546556

Browse files
committed
add word break ii
1 parent 2a6e557 commit b546556

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

word-break-ii/README.md

+37-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,39 @@
1+
## [Word Break](../word-break) with traceback
2+
3+
In order to output all solutions,
4+
just change P from `boolean` to a collection which contains all parent index.
5+
6+
7+
```
8+
0 1 2 3 4 5 6 7 8 9 A
9+
* c a t s a n d d o g
10+
11+
0 0 3 7
12+
4
13+
14+
15+
P[3] = [0]
16+
P[4] = [0]
17+
18+
P[7] = [3, 4]
19+
P[10] = [7]
20+
21+
```
22+
23+
## Recover strings using DFS
24+
25+
To find all strings break at breakpoint, just using DFS to find out them.
26+
27+
* 10, 7, 3, 0: dog sand cat
28+
* 10, 7, 4, 0: dog and cats
29+
30+
### Note:
31+
32+
offsets here is 1 larger than the original offset.
33+
34+
So, `7..10` here is to start form the next element, the 8th to the 11th(exclusive).
35+
36+
Luckily, restore the `S[8th..11th]` is just the same as `S[7..10]`,
37+
Because index of S starts from `0`.
138

2-
## TODO
3-
* write down thinking
439

0 commit comments

Comments
 (0)