首页 > 试题广场 >

possible sentences

[编程题]possible sentences
  • 热度指数:1856 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.
Return all such possible sentences.


输入描述:
s ="catsanddog"
dict ="cat", "cats", "and", "sand", "dog"


输出描述:
[cats and dog, cat sand dog]
示例1

输入

s ="catsanddog"
dict ="cat","cats","and","sand","dog"

输出

[cats and dog, cat sand dog]
头像 牛客题解官
发表于 2020-06-05 15:40:02
精华题解 题目难度:三星 考察点:dfs 方法:dfs 1.题意: 由于给的题面是英文的,所以在这里先简单介绍一下题意,给定一个字符串S和一个包含单词(也是字符串)的字典dic,现在要求 在字符串S中添加若干个空格来组成一个句子,要求构造的单词必须全部在字典dic中出现,输 展开全文