You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cache[s.length] =true// lastPos is true, meaning [array of word length], lastPos] since string "" can be segmented of any list of any words (our dp basecase)
for(i in s.length-1 downTo 0){
for(word in wordDict){
if(word.length+i <= s.length){//enough chars in s for this word to be viable ?
if(word == s.substring(i, i+word.length)){// its the same word char by char?
if(cache[i+word.length] ==true) //this cache index is true only if the cache at index [i+word.length is true]