- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNo434.java
29 lines (26 loc) · 542 Bytes
/
No434.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
packageAlgorithm.leetcode.String;
/**
*
* Created by tujietg on Nov 6, 2019
*/
publicclassNo434 {
publicintcompress(char[] chars) {
intindex = 0;
intendindex = 0;
while (index < chars.length) {
charcurrent = chars[index];
intcount = 0;
while (index < chars.length && current == chars[index]) {
count++;
index++;
}
chars[endindex++] = current;
if (count != 1) {
for (charitem : Integer.toString(count).toCharArray()) {
chars[endindex++] = item;
}
}
}
returnendindex;
}
}