Most solution get TLE with following case


  • 0
    H

    Please add following test case:

    String s = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    String[] words = {"a","aa","aaa","aaaa","aaaaa","aaaaaa","aaaaaaa","aaaaaaaa","aaaaaaaaa","aaaaaaaaaa"};

  • 0
    N

    I got the same issue but thats when DP came in handy.


  • 0
    S

    nice test case. :)


  • 0
    J

    I got TLE with my DP solution as well. The workaround was calling Word Break I function to determine whether the word is breakable first before calling the real breaking function. There's another very smart optimization posted earlier by someone else which checks for the length of the longest word in the dictionary to avoid extra searches.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.