goden1715

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 1 Imported by: 0

README

面试题 17.15.最长单词

1. 题目描述

给定一组单词 words ,编写一个程序,找出其中的最长单词,且该单词由这组单词中的其他单词组合而成。若有多个长度相同的结果,返回其中字典序最小的一项,若没有符合要求的单词则返回空字符串。

示例:

输入: ["cat","banana","dog","nana","walk","walker","dogwalker"]
输出: "dogwalker"
解释: "dogwalker"可由"dog"和"walker"组成。

提示:

  • 0 <= len(words) <= 200
  • 1 <= len(words[i]) <= 100

标签 字典树 数组 哈希表 字符串

2. 解题

此题要求满足两个条件:1. 单词长度最长,2. 单词由几个其他单词组成

对于1,可根据单词长度对单词进行排序,对于2,使用map存储所有单词

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL