美文网首页
139. Word Break

139. Word Break

作者: 刘小小gogo | 来源:发表于2018-09-04 23:48 被阅读0次
    image.png
    参考:https://algorithm.yuanbin.me/zh-hans/dynamic_programming/word_break.html
    image.png
    class Solution {
    public:
        bool wordBreak(string s, vector<string>& wordDict) {
            vector<bool> dp(s.size() + 1, false);
            dp[0] = true;
            for(int i = 1; i <= s.size(); i++){
                for(int j = 0; j < i; j++){
                    if(find(wordDict.begin(), wordDict.end(),s.substr(j, i - j)) != wordDict.end() && dp[j] == true){
                        dp[i] = true;
                        continue;
                    }
                }
            }
            return dp[s.size()];
        }
    };
    

    相关文章

      网友评论

          本文标题:139. Word Break

          本文链接:https://www.haomeiwen.com/subject/bclowftx.html