一、题目地址
https://leetcode-cn.com/problems/word-break/
二、具体代码
var wordBreak &#61; function(s, wordDict) {let len &#61; s.length;let dp &#61; new Array(len &#43; 1).fill(false);dp[0] &#61; true;for(let i&#61;1; i<&#61;len; i&#43;&#43;) {for(let j&#61;i-1; j>&#61;0; j--) {if(dp[i] &#61;&#61;&#61; true) {break;}if(dp[j] &#61;&#61;&#61; false) {continue;}let tempStr &#61; s.slice(j, i);if(dp[j] &#61;&#61;&#61; true && wordDict.includes(tempStr)) {dp[i] &#61; true;break;}}}return dp[len];
};
三、补充链接
https://leetcode-cn.com/problems/word-break/solution/shou-hui-tu-jie-san-chong-fang-fa-dfs-bfs-dong-tai/
四、补充部分
关注公众号&#xff1a;【深漂程序员小庄】&#xff1a;
内含丰富的学习资源和面试经验&#xff08;不限前端、java&#xff09;&#xff0c;还有学习交流群可加&#xff0c;并且还有各大厂大佬可一起交流学习&#xff0c;一起进步&#xff5e;添加小庄微信&#xff0c;回复【加群】&#xff0c;可加入互联网技术交流群&#xff1a;