1 Star 0 Fork 0

wangzai / 力扣算法面试题

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
139. Word Break.cpp 644 Bytes
一键复制 编辑 原始数据 按行查看 历史
wangzai 提交于 2021-11-11 10:13 . 增加了139. 单词拆分
//
// Created by 旺崽 on 2021/11/11.
//
#include "bits/stdc++.h"
using namespace std;
class Solution {
public:
bool wordBreak(string s, vector<string> &wordDict) {
unordered_set<string> dic;
for (auto _: wordDict) dic.insert(_);
vector<bool> dp(s.size() + 1);
dp[0] = 1;
for (int i = 1; i <= s.size(); i++) {
for (int j = 0; j < i; j++) {
if (dp[j] && dic.find(s.substr(j, i - j)) != dic.end()) {
dp[i] = true;
break;
}
}
}
return dp[s.size()];
}
};
int main() {
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/qianlinyi/algorithmicQuestions.git
git@gitee.com:qianlinyi/algorithmicQuestions.git
qianlinyi
algorithmicQuestions
力扣算法面试题
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891