【发布时间】:2018-06-07 13:07:06
【问题描述】:
每个字母只能使用一次。数组中可能有多个相同字母的实例。
我们可以假设字典中的每个单词都可以用字母拼写。目标是返回最大字数。
示例 1:
arr = ['a', 'b', 'z', 'z', 'z', 'z']
dict = ['ab', 'azz', 'bzz']
// returns 2 ( for [ 'azz', 'bzz' ])
示例 2:
arr = ['g', 't', 'o', 'g', 'w', 'r', 'd', 'e', 'a', 'b']
dict = ['we', 'bag', 'got', 'word']
// returns 3 ( for ['we', 'bag', 'got'] )
编辑以明确遵守 SO 准则:
寻找解决方案。我在面试的时候遇到了这个问题。我的解决方案如下,但因为太慢而被拒绝。
1.) For each word in dict, w
- Remove w's letters from the arr.
- With the remaining letters, count how many other words could be spelled.
Put that # as w's "score"
2.) With every word "scored", select the word with the highest score,
remove that word and its letters from the input arrays.
3.) Repeat this process until no more words can be spelled from the remaining
set of letters.
【问题讨论】:
-
你想要python解决方案吗?
-
那么你的问题是什么?你要求我们为你做作业吗?我们很乐意提供帮助,但您需要付出一些努力。请阅读meta.stackoverflow.com/questions/334822/…
-
描述也不清楚并且有错误 - 您可以清楚地创建比示例中提供的更多的单词
-
一个词可以多次使用吗?
-
@squeamishossifrage 这种技术会在第一个示例中找到
azz吗?
标签: algorithm