Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue Dec 15, 2014 · 3 comments
Open

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

ghost opened this issue Dec 15, 2014 · 3 comments

Comments

@ghost
Copy link

ghost commented Dec 15, 2014

vector<string> wordBreak_dp(string s, set<string> &dict) {

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";
@haoel
Copy link
Owner

haoel commented Dec 16, 2014

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

@yqtaowhu
Copy link

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

@ghost
Copy link
Author

ghost commented Sep 23, 2016

@yqtaowhu Sure, just visit the leetcode forum. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants