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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 |
package
huawei; public class StringZip { public
static String stringZip(String a) { String ans = "" ; if (a.equals( null )) { return
"error" ; } else { char
[] b=a.toCharArray(); System.out.println(b.length+ "the len of" ); for ( int
i= 0 ;i<b.length;i++) { int
count= 0 ; while (i+count<b.length&&b[i+count]==b[i]) { count++; } System.out.println(count+ "--before---" +b[i]); ans+=count+ "" +b[i]; i=i+count- 1 ; //System.out.println(b[i]+"--after--"+i); // ans+=count+b[i-1]; } } return
ans; } public
static void main(String[] s) { System.out.println(stringZip( "hhhhellli" )); } } |
HW机试字符串压缩java(1),布布扣,bubuko.com
原文:http://www.cnblogs.com/hansongjiang/p/3590180.html