力扣139

/*

还是和决策树一样,从s的第0个位置开始遍历,

然后只要word是s的子串,那么则置为true,而且要注意边界条件

*/

class Solution {

public:

bool wordBreak(string s, vector<string>& wordDict) {

vector<bool> dp(s.length()+1,false);

dp0=true;

for(int i=0;i<s.length();i++){

for(auto word : wordDict){

if(dpi&&(i+word.length()<=s.length())&&word==s.substr(i,word.length())){

dpi+word.length()=dpi;

}

}

}

return dps.length();

}

};

相关推荐
爱读书的小胖1 小时前
LeetCode 122:买卖股票的最佳时机 II(C)解题分析
算法
结局无敌1 小时前
React Native for OpenHarmony 实战:三方库 react-native-modal-dialog 的鸿蒙化适配指南
深度学习·算法·react native·react.js·harmonyos
ychqsq2 小时前
234.无题
经验分享·职场和发展
OPEN-F2 小时前
ROS2系列教程:上位机建图与导航(原理综合)
算法·机器人
weixin_307779132 小时前
C++代码实现MATLAB中的fitrtree函数功能
开发语言·c++·算法·matlab
tomwang03222 小时前
路径优化建模、优化算法分类及工程化小结
算法·数学建模·分类
小羊没烦恼!2 小时前
Ajax与JSON的一些总结
android·java·前端·数据库·mysql·算法·okhttp
考研保研资料分享2 小时前
物理保研至中科大:固体物理复习、四场面试与科研追问
面试·职场和发展
2501_926978332 小时前
人机通信协议--人和机器之间的交互想象
人工智能·经验分享·算法·ai写作
行者全栈架构师3 小时前
【鸿蒙心迹】互动卡片全链路——把核心功能放到桌面(FormKit 实战)(HarmonyOS 7.x)
前端·算法·架构