411. Minimum Unique Word Abbreviation

Posted 日常任务

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了411. Minimum Unique Word Abbreviation相关的知识,希望对你有一定的参考价值。

A string such as "word" contains the following abbreviations:

["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"]

Given a target string and a set of strings in a dictionary, find an abbreviation of this target string with the smallest possible length such that it does not conflict with abbreviations of the strings in the dictionary.

Each number or letter in the abbreviation is considered length = 1. For example, the abbreviation "a32bc" has length = 4.

Note:

  • In the case of multiple answers as shown in the second example below, you may return any one of them.
  • Assume length of target string = m, and dictionary size = n. You may assume that m ≤ 21, n ≤ 1000, and log2(n) + m ≤ 20.

 

Examples:

"apple", ["blade"] -> "a4" (because "5" or "4e" conflicts with "blade")

"apple", ["plain", "amber", "blade"] -> "1p3" (other valid answers include "ap3", "a3e", "2p2", "3le", "3l1").


以上是关于411. Minimum Unique Word Abbreviation的主要内容,如果未能解决你的问题,请参考以下文章

411. Minimum Unique Word Abbreviation

Leetcode: Minimum Unique Word Abbreviation

Codeforces Round #411 (Div. 2)D. Minimum number of steps(贪心)

62. 63. Unique Paths 64. Minimum Path Sum

leetcode1647. Minimum Deletions to Make Character Frequencies Unique

945. Minimum Increment to Make Array Unique