Commit 47030270 authored by zhayao's avatar zhayao
Browse files

keep going

parent beb751fa
......@@ -1670,17 +1670,35 @@ Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6-
Word Break
class Solution {
public:
bool wordBreak(string s, vector<string>& wordDict) {
unordered_set<string> dict;
for(auto &key: wordDict){
dict.insert(key);
}
vector<bool> matched(s.size(), false);
int last_match_pos = 0;
for(int i=0; i<s.size(); i++){
string sub = s.substr(last_match_pos, i-last_match_pos);
cout<<sub<<endl;
auto it = dict.find(sub);
if(it != dict.end()){
dict.
for(int inner=0; inner<sub.size(); inner++){
matched[inner+last_match_pos] = true;
}
last_match_pos = i+1;
}
}
for(int i=0; i<matched.size(); i++){
if(!matched[i]) return false;
}
return true;
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment