标签:dbr span rdb length 返回结果 class return ret contain
139. Word Break
返回结果较为简单可用dp, 复杂用dfs
class Solution { public boolean wordBreak(String s, List<String> wordDict) { boolean[] dp = new boolean[s.length() + 1]; dp[0] = true; //枚举所有substring for(int i = 1; i <= s.length(); i++){ for(int j = 0; j < i; j++){ if(dp[j] && wordDict.contains(s.substring(j, i))){ dp[i] = true; break; } } } return dp[s.length()]; } }
标签:dbr span rdb length 返回结果 class return ret contain
原文地址:https://www.cnblogs.com/Afei-1123/p/12010273.html