当前位置:网站首页>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 又到周五了,双休的日子时间飞快
边栏推荐
猜你喜欢

打败 二叉树!

Unit contour creation method

Dragon lizard developer said: first time you got an electric shock, so you are such a dragon lizard community| Issue 8

融云通信“三板斧”,“砍”到了银行的心坎上

21set classic case

Rongyun communication has "hacked" into the heart of the bank

Google waymo proposed r4d: remote distance estimation using reference target

Overview of SAP marketing cloud functions (III)

如何解决 Iterative 半监督训练 在 ASR 训练中难以落地的问题丨RTC Dev Meetup

A review of text contrastive learning
随机推荐
[untitled]
数商云:加强供应商管理,助推航空运输企业与供应商高效协同
Autorf: learn the radiation field of 3D objects from single view (CVPR 2022)
杰理之无缝循环播放【篇】
`Thymeleaf`模板引擎全面解析
Jerry's infrared filtering [chapter]
[learn ZABBIX from scratch] I. Introduction and deployment of ZABBIX
Antd checkbox, limit the selected quantity
数据库注意事项
Unity 热力图建立方法
杰理之可能出现有些芯片音乐播放速度快【篇】
在线文本实体抽取能力,助力应用解析海量文本数据
Operation of simulated examination platform of examination question bank for B certificate of Jiangxi provincial safety officer in 2022
In the era of knowledge economy, it will teach you to do well in knowledge management
Home office should be more efficient - automated office perfectly improves fishing time | community essay solicitation
Promotion of Project Manager
鲲鹏arm服务器编译安装PaddlePaddle
puzzle(016.2)指画星河
pip uninstall all packages except builtin package
HarmonyOS.2