LeetCode 139: Word Break

Posted keepshuatishuati

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LeetCode 139: Word Break相关的知识,希望对你有一定的参考价值。

class Solution {
    public boolean wordBreak(String s, List<String> wordDict) {
        if (s == null || s.length() == 0) {
            return false;
        }
        
        boolean[] canBreak = new boolean[s.length() + 1];
        canBreak[0] = true;
        for (int i = 1; i <= s.length(); i++) {
            for (int j = i - 1; j >= 0; j--) {
                if (canBreak[j] && wordDict.contains(s.substring(j, i))) {
                    canBreak[i] = true;
                    break;
                }
            }
        }
        return canBreak[s.length()];
    }
}

 

以上是关于LeetCode 139: Word Break的主要内容,如果未能解决你的问题,请参考以下文章

LeetCode 139 Word Break

LeetCode #139. Word Break C#

Leetcode 139. Word Break

LeetCode 139: Word Break

leetcode 139. Word Break

LeetCode-139-Word Break