bool wordBreak(char * s, char ** wordDict, int wordDictSize){ int i=0, j, len=strlen(s); int stack[10000], left=0, right=0, val=0; stack[right++]=0; int hash[1000]={0}; while(left<right){ i=stack[left++]; if (hash[i]==1) continue; for (j=0; j<wordDictSize; j++) { if(s+i == strstr(s+i,wordDict[j])){ val=i+strlen(wordDict[j]); if(val == len) return true; if (hash[val]==0) stack[right++]=i+strlen(wordDict[j]); } } if(j==wordDictSize) hash[i]=1; } return false; }
bool wordBreak(char * s, char ** wordDict, int wordDictSize){ int i=0, j, len=strlen(s); int stack[10000], left=0, right=0, val=0; stack[right++]=0; int hash[1000]={0}; while(left<right){ i=stack[left++]; if (hash[i]==1) continue; for (j=0; j<wordDictSize; j++) { if(s+i == strstr(s+i,wordDict[j])){ val=i+strlen(wordDict[j]); if(val == len) return true; if (hash[val]==0) stack[right++]=i+strlen(wordDict[j]); } } if(j==wordDictSize) hash[i]=1; } return false; }