|
3 | 3 | import java.util.ArrayList;
|
4 | 4 | import java.util.List;
|
5 | 5 |
|
6 |
| -/** |
7 |
| - * 411. Minimum Unique Word Abbreviation |
8 |
| - * |
9 |
| - * A string such as "word" contains the following abbreviations: |
10 |
| -
|
11 |
| - ["word", "1ord", "w1rd", "wo1d", "wor1", "2rd", "w2d", "wo2", "1o1d", "1or1", "w1r1", "1o2", "2r1", "3d", "w3", "4"] |
12 |
| -
|
13 |
| - Given a target string and a set of strings in a dictionary, |
14 |
| - find an abbreviation of this target string with the smallest possible length such |
15 |
| - that it does not conflict with abbreviations of the strings in the dictionary. |
16 |
| -
|
17 |
| - Each number or letter in the abbreviation is considered length = 1. For example, the abbreviation "a32bc" has length = 4. |
18 |
| -
|
19 |
| - Note: |
20 |
| -
|
21 |
| - In the case of multiple answers as shown in the second example below, you may return any one of them. |
22 |
| - Assume length of target string = m, and dictionary size = n. You may assume that m ≤ 21, n ≤ 1000, and log2(n) + m ≤ 20. |
23 |
| -
|
24 |
| - Examples: |
25 |
| -
|
26 |
| - "apple", ["blade"] -> "a4" (because "5" or "4e" conflicts with "blade") |
27 |
| -
|
28 |
| - "apple", ["plain", "amber", "blade"] -> "1p3" (other valid answers include "ap3", "a3e", "2p2", "3le", "3l1"). |
29 |
| - * |
30 |
| - */ |
31 | 6 | public class _411 {
|
32 | 7 | public static class Solution1 {
|
33 |
| - /** Credit: https://discuss.leetcode.com/topic/61346/trie-bruteforce */ |
| 8 | + /** |
| 9 | + * Credit: https://discuss.leetcode.com/topic/61346/trie-bruteforce |
| 10 | + */ |
34 | 11 | class Trie {
|
35 | 12 | Trie[] children = new Trie[26];
|
36 | 13 | boolean isWord = false;
|
@@ -114,7 +91,7 @@ public void abbrGenerator(String target, int i, String tmp, int abbr, int num) {
|
114 | 91 | }
|
115 | 92 | char cur = target.charAt(i);
|
116 | 93 | abbrGenerator(target, i + 1, abbr == 0 ? tmp + cur : tmp + abbr + cur, 0,
|
117 |
| - abbr == 0 ? num - 1 : num - 2); |
| 94 | + abbr == 0 ? num - 1 : num - 2); |
118 | 95 | abbrGenerator(target, i + 1, tmp, abbr + 1, num);
|
119 | 96 | }
|
120 | 97 | }
|
|
0 commit comments