Advertisement
otot957

Untitled

Feb 15th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     bool wordBreak(string s, vector<string>& wordDict) {
  4.         if(wordDict.size()==0 || s.size()==0)
  5.             return false;
  6.         int j=0, i=0;
  7.         vector<bool> found(s.size(),false);
  8.         while(i<s.size() && j<s.size()){
  9.             if(find(wordDict.begin(), wordDict.end(),s.substr(i,j))==wordDict.end()){
  10.                 j++;
  11.                 cout<<s.substr(i,j)<<" "<<j<<" "<<i<<endl;
  12.             }
  13.             else {
  14.                 for(int k=i; k<i+j; k++){
  15.                     found[k]=true;
  16.                 }
  17.                 i=i+j;
  18.                 j=0;
  19.             }
  20.         }
  21.         for(int k=0; k<found.size(); k++){
  22.             cout<<found[k]<<endl;
  23.             if(found[k]==false)
  24.                 return false;
  25.         }
  26.         return true;
  27.     }
  28. };
  29. /*
  30.  
  31. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement