当前位置:网站首页>leetcode 139. Word Break 单词拆分(中等)
leetcode 139. Word Break 单词拆分(中等)
2022-06-24 13:02:00 【InfoQ】
一、题目大意
- 1 <= s.length <= 300
- 1 <= wordDict.length <= 1000
- 1 <= wordDict[i].length <= 20
- s 和 wordDict[i] 仅有小写英文字母组成
- wordDict 中的所有字符串 互不相同
二、解题思路
三、解题方法
3.1 Java实现
public class Solution {
public boolean wordBreak(String s, List<String> wordDict) {
int n = s.length();
boolean[] dp = new boolean[n + 1];
dp[0] = true;
for (int i = 1; i <= n; i++) {
for (String tmp : wordDict) {
int len = tmp.length();
if (i>=len && tmp.equals(s.substring(i - len, i))) {
dp[i] = dp[i] || dp[i - len];
}
}
}
return dp[n];
}
}
四、总结小记
- 2022/6/24 又到周五了,双休的日子时间飞快
边栏推荐
- Jericho After sleep, the system will wake up regularly and continue to run without resetting [chapter]
- HarmonyOS.2
- conda和pip命令
- 【无标题】
- Kotlin coordination channel
- 百度地图API绘制点及提示信息
- 数字臧品系统开发 NFT数字臧品系统异常处理源码分享
- 2022 Quality Officer - Equipment direction - post skills (Quality Officer) recurrent training question bank and online simulation examination
- MIT-6.824-lab4A-2022(万字讲解-代码构建)
- Autorf: learn the radiation field of 3D objects from single view (CVPR 2022)
猜你喜欢
随机推荐
Research and development practice of Kwai real-time data warehouse support system
2022 recurrent training question bank and answers for hoisting signal Rigger (special type of construction work)
**Puzzling little problem in unity - light and sky box
如何解决 Iterative 半监督训练 在 ASR 训练中难以落地的问题丨RTC Dev Meetup
鲲鹏arm服务器编译安装PaddlePaddle
Rongyun communication has "hacked" into the heart of the bank
Baidu map API drawing points and tips
4个不可不知的“安全左移”的理由
Zhiyuan community weekly 86: Gary Marcus talks about three linguistic factors that can be used for reference in large model research; Google puts forward the Wensheng graph model parti which is compar
conda和pip命令
Explain kubernetes backup and recovery tools velero | learn more about carina series phase III
Overview of SAP marketing cloud functions (III)
杰理之增加一个输入捕捉通道【篇】
【比特熊故事汇】6月MVP英雄故事|技术实践碰撞境界思维
数据库注意事项
记录一次Mongotemplate的And和Or的各种套
从谭浩强《C程序设计》上摘录的ASCII码表(常用字符与ASCII代码对照表)
SAP Marketing Cloud 功能概述(四)
greendao使用问题
AntD checkbox,限制选中数量


![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)






