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 8b220f0 + 8090ae1 commit 4db1891Copy full SHA for 4db1891
2018.11.29-leetcode443/我爱吃瓜子.md
@@ -0,0 +1,37 @@
1
+#leetcode 443
2
+、、、
3
+class Solution {
4
+ public int compress(char[] chars) {
5
+ int count =1;
6
+ int index= 0;
7
+ for(int i=0;i<chars.length;i++){
8
+
9
+ //判断是否最后一个 或者 判断是否重复的最后一个
10
+ if(i+1 == chars.length || chars[i]!=chars[i+1]){
11
12
13
14
+ //将字母赋值到结果字符数组中
15
+ chars[index++]=chars[i];
16
17
+ //判断是否需要将数量赋值到数组中
18
+ if(count>1){
19
+ //int转为String
20
+ String temp =String.valueOf(count);
21
22
+ //将数量赋值到结果数组中
23
+ for(int z=0;z<temp.length();z++){
24
+ //获取字符串中某个下标的字符
25
+ chars[index++] =temp.charAt(z);
26
+ }
27
+ //初始化数量
28
+ count=1;
29
30
+ }else{ //字符重复中
31
+ count++;
32
33
34
+ return index;
35
+}
36
37
0 commit comments