题目:
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.
For example, givens = "leetcode",dict = ["leet", "code"].
Return true because "leetcode" can be segmented as "leet
code".
思路:
之前想到的是使用循环一个一个试,对每个dict中 的元素进行s.contains的判断。然后再做处理。
但是,毫无疑问的超时了。原因就在于,做了太多的重复性工作。
如果验证样例中输入:baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa......
阅读全文