Skip to content

Commit 7bf9ce3

Browse files
refactor 411
1 parent de039b2 commit 7bf9ce3

File tree

1 file changed

+4
-27
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-27
lines changed

src/main/java/com/fishercoder/solutions/_411.java

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,11 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

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-
*/
316
public class _411 {
327
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+
*/
3411
class Trie {
3512
Trie[] children = new Trie[26];
3613
boolean isWord = false;
@@ -114,7 +91,7 @@ public void abbrGenerator(String target, int i, String tmp, int abbr, int num) {
11491
}
11592
char cur = target.charAt(i);
11693
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);
11895
abbrGenerator(target, i + 1, tmp, abbr + 1, num);
11996
}
12097
}

0 commit comments

Comments
 (0)