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, given
s ="leetcode"
,dict = ["leet", "code"]
. Return true because "leetcode"
can be segmented as "leet code"
.
算法:在网上查到的,动态规划算法
1 class Solution { 2 public: 3 bool wordBreak(string s, unordered_set&dict) { 4 int len=s.size(); 5 bool *k=new bool[s.size()]; 6 memset(k,false,s.size()); 7 for(int i=0;i