Answers for "word break leetcode"

1

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);
            }
        }
    }
Posted by: Guest on June-02-2021

Browse Popular Code Answers by Language