※ 引述《Rushia (早瀬ユウカの体操服 )》之铭言:
: https://leetcode.com/problems/replace-words/description
: 648. Replace Words
: 给你一个字串行表dictionary和一个字串sentence,sentence里面有很多单字,这些单字
: 被空白分割,有些单字是从其他单字的字首延伸的例如:helpful = help+ful 若
: sentence里面的单字字首存在于dictionary我们可以把原单字替换成较短的字首,若
: 存在多个字首则取最短,求出替换完的句子长什么样子。
: Example 1:
: Input: dictionary = ["cat","bat","rat"], sentence = "the cattle was rattled
: by the battery"
: Output: "the cat was rat by the bat"
: 思路:
: 1.前面忘了中间忘了凭印象手刻一个字典树,先把所有字根加入字典树。
: 2.接下来把sentence依照空白切成单字,如果这个单字在字典树里面就加入第一个找到的
: 字根,找不到就返回原单字。
: 3.把结果集串起来用空白分割。
: java code
: