Skip to content

Commit c805826

Browse files
add 820
1 parent ec5a38e commit c805826

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ _If you like this project, please leave me a star._ ★
421421
|832|[Flipping an Image](https://leetcode.com/problems/flipping-an-image/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_832.java) | |Easy|
422422
|830|[Positions of Large Groups](https://leetcode.com/problems/positions-of-large-groups/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_830.java) | |Easy|
423423
|824|[Goat Latin](https://leetcode.com/problems/goat-latin/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_824.java) | |Easy|
424-
|821|[Shortest Distance to a Character](https://leetcode.com/problems/shortest-distance-to-a-character/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_821.java) | |Easy|
424+
|821|[Shortest Distance to a Character](https://leetcode.com/problems/shortest-distance-to-a-character/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_821.java) | |Easy|
425+
|820|[Short Encoding of Words](https://leetcode.com/problems/short-encoding-of-words/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_820.java) | |Medium|
425426
|819|[Most Common Word](https://leetcode.com/problems/most-common-word/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_819.java) | |Easy| HashMap
426427
|814|[Binary Tree Pruning](https://leetcode.com/problems/binary-tree-pruning/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_814.java) | |Medium| recursion, DFS
427428
|811|[Subdomain Visit Count](https://leetcode.com/problems/subdomain-visit-count/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_811.java) | |Easy| HashMap
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
5+
public class _820 {
6+
public static class Solution1 {
7+
public int minimumLengthEncoding(String[] words) {
8+
Arrays.sort(words, (a, b) -> a.length() - b.length());
9+
boolean[] removed = new boolean[words.length];
10+
for (int j = words.length - 2; j >= 0; j--) {
11+
for (int i = j + 1; i < words.length; i++) {
12+
if (!removed[i]) {
13+
if (words[i].substring(words[i].length() - words[j].length()).equals(words[j])) {
14+
removed[j] = true;
15+
break;
16+
}
17+
}
18+
}
19+
}
20+
int len = 0;
21+
for (int i = 0; i < words.length; i++) {
22+
if (!removed[i]) {
23+
len += words[i].length();
24+
len++;
25+
}
26+
}
27+
return len;
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy