Advertisement
otot957

Untitled

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