File tree 1 file changed +0
-40
lines changed
src/main/java/com/fishercoder/solutions 1 file changed +0
-40
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
- /**
4
- * 471. Encode String with Shortest Length
5
- *
6
- Given a non-empty string, encode the string such that its encoded length is the shortest.
7
-
8
- The encoding rule is: k[encoded_string], where the encoded_string inside the square
9
- brackets is being repeated exactly k times.
10
-
11
- Note:
12
- k will be a positive integer and encoded string will not be empty or have extra space.
13
- You may assume that the input string contains only lowercase English letters. The string's length is at most 160.
14
- If an encoding process does not make the string shorter,
15
- then do not encode it. If there are several solutions, return any of them is fine.
16
-
17
- Example 1:
18
-
19
- Input: "aaa"
20
- Output: "aaa"
21
- Explanation: There is no way to encode it such that it is shorter than the input string, so we do not encode it.
22
- Example 2:
23
-
24
- Input: "aaaaa"
25
- Output: "5[a]"
26
- Explanation: "5[a]" is shorter than "aaaaa" by 1 character.
27
- Example 3:
28
-
29
- Input: "aaaaaaaaaa"
30
- Output: "10[a]"
31
- Explanation: "a9[a]" or "9[a]a" are also valid solutions, both of them have the same length = 5, which is the same as "10[a]".
32
- Example 4:
33
-
34
- Input: "aabcaabcd"
35
- Output: "2[aabc]d"
36
- Explanation: "aabc" occurs twice, so one answer can be "2[aabc]d".
37
- Example 5:
38
-
39
- Input: "abbbabbbcabbbabbbc"
40
- Output: "2[2[abbb]c]"
41
- Explanation: "abbbabbbc" occurs twice, but "abbbabbbc" can also be encoded to "2[abbb]c", so one answer can be "2[2[abbb]c]".
42
- */
43
3
public class _471 {
44
4
45
5
public static class Solution1 {
You can’t perform that action at this time.
0 commit comments