leetcode icon indicating copy to clipboard operation
leetcode copied to clipboard

[Word Break II] Your code seems outdated and needs more test cases.

Open ghost opened this issue 11 years ago • 3 comments

https://github.com/haoel/leetcode/blob/0858fdb3d9c4dba43135001e370a80ce518d5e82/src/wordBreak/wordBreak.II.cpp#L143

Your DP solution is not really efficient.

I can provide two test cases:

unordered_set<string> dict = {"a","aa","ab"};
string s = "babaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
unordered_set<string> dict = {"a","aa","ba"};
string s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabab";

ghost avatar Dec 15 '14 20:12 ghost

You are right, the DP is not efficient. Actually, the recursive solution is more efficient than that DP solution.

haoel avatar Dec 16 '14 01:12 haoel

yes,i think the dp is not efficient , it will lead Memory Limit Exceeded, could you have any solution to solve it .

yqtaowhu avatar Sep 23 '16 09:09 yqtaowhu

@yqtaowhu Sure, just visit the leetcode forum. 😉

ghost avatar Sep 23 '16 17:09 ghost