Word Break (print all ways) leetcode code example
Example: word break leetcode
void helper(String s, int start, List<String> wordDict, List<String> slate)
{
if(start==s.length())
{
result.add(String.join(" ",(slate)));
return;
}
for(int i=start;i<s.length();i++)
{
String word = s.substring(start, i+1);
if(wordDict.contains(word))
{
slate.add(word);
helper(s, i+1,wordDict, slate);
slate.remove(slate.size()-1);
}
}
}