Open yokostan opened 5 years ago
DP:
class Solution { public boolean wordBreak(String s, List<String> wordDict) { boolean[] f = new boolean[s.length() + 1]; f[0] = true; for (int i = 1; i <= s.length(); i++) { for (int j = 0; j < i; j++) { if (f[j] && wordDict.contains(s.substring(j, i))) { f[i] = true; break; } } } return f[s.length()]; } }
DP kinda has a template as well. This is easier compared to #163
DP:
DP kinda has a template as well. This is easier compared to #163