当前位置:网站首页>leetcode 139. Word break word split (medium)
leetcode 139. Word break word split (medium)
2022-06-24 14:28:00 【InfoQ】
One 、 The main idea of the topic
- 1 <= s.length <= 300
- 1 <= wordDict.length <= 1000
- 1 <= wordDict[i].length <= 20
- s and wordDict[i] Only lowercase letters
- wordDict All the strings in Different from each other
Two 、 Their thinking
3、 ... and 、 How to solve the problem
3.1 Java Realization
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];
}
}
Four 、 Summary notes
- 2022/6/24 It's Friday again , The weekend is fast
边栏推荐
- Three efficient programming skills of go language
- [ansible problem processing] remote execution user environment variable loading problem
- 实战 | 记一次曲折的钓鱼溯源反制
- MES在流程和离散制造企业的15个差别(下)
- 10_那些格調很高的個性簽名
- R language plot visualization: use plot to visualize the training set and test set after data division, use different shape label representation, training set, test set, and display training and test
- How to evaluate domestic reporting tools and Bi software
- MySQL title
- 如何避免下重复订单
- 专精特新“小巨人”再启动,“企业上云”数字赋能
猜你喜欢

日常知识科普

打败 二叉树!

Laravel8 uses faker to call factory to fill data

Application of motion capture system in positioning and mapping of mobile robot in underground tunnel

左手代码,右手开源,开源路上的一份子

How to avoid placing duplicate orders

Digital business cloud: strengthen supplier management and promote efficient collaboration between air transport enterprises and suppliers

Common singleton mode & simple factory

ES mapping之keyword;term查詢添加keyword查詢;更改mapping keyword類型

postgresql之词法分析简介
随机推荐
MySQL log management, backup and recovery
【比特熊故事汇】6月MVP英雄故事|技术实践碰撞境界思维
P2pdb white paper
阿里OSS对象存储服务
ESP32系列--ESP32各个系列对比
A review of text contrastive learning
ssh-keygen 配置无需每次输入密码
leetcode.12 --- 整数转罗马数字
Development of digital Tibetan product system NFT digital Tibetan product system exception handling source code sharing
June training (day 24) - segment tree
一文搞定 UDP 和 TCP 高频面试题!
Convolution kernel and characteristic graph visualization
Puzzle (016.2) finger painting Galaxy
Mots clés pour la cartographie es; Ajouter une requête par mot - clé à la requête term; Changer le type de mot - clé de cartographie
Don't underestimate the integral mall. It can play a great role
box-sizing
[leetcode] 10. Regular expression matching
ASCII code table extracted from tanhaoqiang's C program design (comparison table of common characters and ASCII codes)
Database considerations
R language constructs regression model diagnosis (normality is invalid), performs variable transformation, and uses powertransform function in car package to perform box Cox transform to normality on