感觉这个板块要重新刷,完全没有印象
- class Solution {
- public boolean wordBreak(String s, List
wordDict) { - Set
set = new HashSet<>(wordDict); - boolean[] dp = new boolean[s.length() + 1];
- dp[0] = true;
-
- for (int i = 1; i <= s.length(); i++) {
- for (int j = 0; j < i; j++) {
- String word = s.substring(j, i);
- if (set.contains(word) && dp[j] == true) {
- dp[i] = true;
- }
- }
- }
- return dp[s.length()];
- }
- }