We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents b698c23 + c18c29e commit 27ad47eCopy full SHA for 27ad47e
2018.11.29-leetcode443/杨.md
@@ -0,0 +1,34 @@
1
+```
2
+public int compress(char[] chars) {
3
+ char data = chars[0];
4
+ int index = 0;
5
+ int length = -1;
6
+ if(chars.length == 1){
7
+ return 1;
8
+ }else {
9
+ for (int i = 1;i< chars.length;i++){
10
+ if(chars[i]!=data || i == chars.length-1){
11
+ chars[++length]=data;
12
+ if(i == chars.length -1 && chars[i]==data){
13
+ i++;
14
+ }
15
+ if(i-index>1){
16
+ char[] num = String.valueOf((i-index)).toCharArray();
17
+ for (int j=0;j<num.length;j++){
18
+ chars[++length] = num[j];
19
20
21
+ if(i < chars.length - 1){
22
+ data = chars[i];
23
+ index = i;
24
25
+ if(i == chars.length -1 && chars[i]!=data){
26
+ chars[++length]=chars[i];
27
28
29
30
31
+ return length + 1;
32
+}
33
+
34
0 commit comments