-
Notifications
You must be signed in to change notification settings - Fork 0
/
139.cpp
35 lines (32 loc) · 854 Bytes
/
139.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Solution {
public:
bool wordBreak(string s, vector<string>& wordDict) {
int len = s.size();
cout << len << endl;
bool *b = new bool[len+1];
b[0] = true;
for(int i = 1; i <= len; ++i)
b[i] = false;//不初始化会RT
set<string> ss;
for(int i = 0; i < wordDict.size(); ++i)
{
ss.insert(wordDict[i]);
}
for(int i = 1; i <= len; ++i)
{
for(int j = i; j >= 1; --j)
{
string tmp = s.substr(j-1, i-j+1);
cout << j << endl;
if(ss.find(tmp) != ss.end() && b[j-1])
{
b[i] = true;
break;
}
}
}
return *(b + len);
//return b[5];
//return b[0];
}
};