|
| bool | wordBreak (string s, vector< string > &wordDict) |
| |
Definition at line 8 of file main.cpp.
◆ wordBreak()
| bool Solution::wordBreak |
( |
string |
s, |
|
|
vector< string > & |
wordDict |
|
) |
| |
|
inline |
Definition at line 11 of file main.cpp.
12 {
13
14 vector<bool> array(s.length() + 1, false);
15
16
17 array[0] = true;
18
19 for (int i = 0; i <= (int)s.length(); ++i)
20 {
21
22 if (!array[i])
23 continue;
24
25
26 for (string& word: wordDict)
27 {
28 int end = i + (int)word.length();
29
30 if (end <= (int)s.length() && s.substr(i, word.length()) == word)
31 array[end] = true;
32 }
33 }
34
35
36
37
38
39
40 return array[s.length()];
41 }
Referenced by main().
The documentation for this class was generated from the following file: