-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Labels
Description
LeetCode 用户名
Michael Liu
问题号码、标题和链接
https://leetcode.cn/problems/word-break/description/?envType=study-plan-v2&envId=top-100-liked
Bug Category
不正确的测试用例 (根据问题陈述,测试用例的输出不正确)
描述
如上图,同样的数据,测试可以通过,但是提交就有问题
你使用的语言
C++
你提交或者运行的代码
#include<bits/stdc++.h>
int dp[350];
class Solution {
public:
bool wordBreak(string s, vector<string>& wordDict) {
int n=s.length();
dp[0]=1;
for(int j=0;j<wordDict.size();j++)
{
if(s.substr(0,wordDict[j].length())==wordDict[j])
{
dp[wordDict[j].length()]=1;
}
}
for(int i=1;i<=n;i++)
{
for(int j=0;j<wordDict.size();j++)
{
int len=wordDict[j].length();
if(i-1-len>=0)
{
if(dp[i-len]==1)
{
if(s.substr(i-len,len)==wordDict[j])
{
dp[i]=1;
break;
}
}
}
}
}
if(dp[n]==1)
{
return true;
}
else
{
return false;
}
}
};期望行为
修正bug
屏幕截图
No response
额外的上下文
No response