Skip to content

Commit 57b205d

Browse files
authored
Create 820. Short Encoding of Words.java
1 parent 9c3346f commit 57b205d

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// O(N*W^2)
2+
3+
import java.util.*;
4+
5+
class Solution {
6+
public int minimumLengthEncoding(String[] words) {
7+
Set<String> set = new HashSet<>(Arrays.asList(words));
8+
for (String word : words) {
9+
for (int i = 1; i < word.length(); i++) {
10+
set.remove(word.substring(i));
11+
}
12+
}
13+
int len = 0;
14+
for (String word : set) {
15+
len += word.length() + 1;
16+
}
17+
return len;
18+
}
19+
}

0 commit comments

Comments
 (0)