Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Word break: https://leetcode.com/problems/word-break/
- class Solution {
- public:
- bool wordBreak(string s, vector<string>& wordDict) {
- if(wordDict.size()==0 || s.size()==0)
- return false;
- int j=0, i=0;
- vector<bool> found(s.size(),false);
- while(i<s.size() && j<s.size()){
- if(find(wordDict.begin(), wordDict.end(),s.substr(i,j))==wordDict.end()){
- j++;
- cout<<s.substr(i,j)<<" "<<j<<" "<<i<<endl;
- }
- else {
- for(int k=i; k<i+j; k++){
- found[k]=true;
- }
- i=i+j;
- j=0;
- }
- }
- for(int k=0; k<found.size(); k++){
- cout<<found[k]<<endl;
- if(found[k]==false)
- return false;
- }
- return true;
- }
- };
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement