forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_820.java
30 lines (28 loc) · 989 Bytes
/
_820.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.fishercoder.solutions;
import java.util.Arrays;
public class _820 {
public static class Solution1 {
public int minimumLengthEncoding(String[] words) {
Arrays.sort(words, (a, b) -> a.length() - b.length());
boolean[] removed = new boolean[words.length];
for (int j = words.length - 2; j >= 0; j--) {
for (int i = j + 1; i < words.length; i++) {
if (!removed[i]) {
if (words[i].substring(words[i].length() - words[j].length()).equals(words[j])) {
removed[j] = true;
break;
}
}
}
}
int len = 0;
for (int i = 0; i < words.length; i++) {
if (!removed[i]) {
len += words[i].length();
len++;
}
}
return len;
}
}
}