每日5题单词拆分
Posted Alice_yufeng
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了每日5题单词拆分相关的知识,希望对你有一定的参考价值。
class Solution
public boolean wordBreak(String s, List<String> wordDict)
boolean[] dp = new boolean[s.length()+1];//默认初始化为false
int n = s.length();
dp[0] = true;
for(int index = 0;index< n;index++)
if(dp[index]==true)
for(int j = index+1;j<n+1;j++)
if(wordDict.contains(s.substring(index,j)))
dp[j] = true;
return dp[n];
以上是关于每日5题单词拆分的主要内容,如果未能解决你的问题,请参考以下文章