Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5ee0e5b

Browse files
refactor 443
1 parent a87db31 commit 5ee0e5b

File tree

1 file changed

+3
-43
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-43
lines changed

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

+3-43
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,11 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 443. String Compression
5-
*
6-
* Given an array of characters, compress it in-place.
7-
* The length after compression must always be smaller than or equal to the original array.
8-
* Every element of the array should be a character (not int) of length 1.
9-
* After you are done modifying the input array in-place, return the new length of the array.
103

11-
Example 1:
12-
Input:
13-
["a","a","b","b","c","c","c"]
14-
15-
Output:
16-
Return 6, and the first 6 characters of the input array should be: ["a","2","b","2","c","3"]
17-
18-
Explanation:
19-
"aa" is replaced by "a2". "bb" is replaced by "b2". "ccc" is replaced by "c3".
20-
21-
Example 2:
22-
Input:
23-
["a"]
24-
25-
Output:
26-
Return 1, and the first 1 characters of the input array should be: ["a"]
27-
28-
Explanation:
29-
Nothing is replaced.
30-
31-
Example 3:
32-
Input:
33-
["a","b","b","b","b","b","b","b","b","b","b","b","b"]
34-
35-
Output:
36-
Return 4, and the first 4 characters of the input array should be: ["a","b","1","2"].
37-
38-
Explanation:
39-
Since the character "a" does not repeat, it is not compressed. "bbbbbbbbbbbb" is replaced by "b12".
40-
Notice each digit has it's own entry in the array.
41-
42-
Note:
43-
All characters have an ASCII value in [35, 126].
44-
1 <= len(chars) <= 1000.
45-
*/
464
public class _443 {
475
public static class Solution1 {
48-
/**This is breaking the rules, it's not in-place.*/
6+
/**
7+
* This is breaking the rules, it's not in-place.
8+
*/
499
public int compress(char[] chars) {
5010
if (chars == null || chars.length == 0) {
5111
return 0;

0 commit comments

Comments
 (0)